Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions bubblesort.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <stdio.h>

void print(int a[], int n) // function to print array elements
{
int i;
for (i = 0; i < n; i++)
{
printf("%d ", a[i]);
}
}
void bubble(int a[], int n) // function to implement bubble sort
{
int i, j, temp;
for (i = 0; i < n; i++)
{
for (j = i + 1; j < n; j++)
{
if (a[j] < a[i])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
}
void main()
{
int i, j, temp;
int a[5] = {12, 37, 35, 16, 28};
int n = sizeof(a) / sizeof(a[0]);
printf("Before sorting array elements are - \n");
print(a, n);
bubble(a, n);
printf("\nAfter sorting array elements are - \n");
print(a, n);
}