-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbubble.c
49 lines (46 loc) · 812 Bytes
/
bubble.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include<stdio.h>
int a[10],n;
void swap(int *a, int *b)
{
int temp;
temp = *a;
*a = *b;
*b = temp;
}
void print_arr(int a[],int n)
{
for(int i=0;i<n;i++)
{
printf("%d\t",a[i]);
}
printf("\n");
}
void bubble_sort(int a[],int n)
{
for(int i=0;i<n-1;i++)
{
for(int j=0;j<n-1;j++)
{
if(a[j]>a[j+1])
{
swap(&a[j],&a[j+1]);
}
}
printf("Pass %d : ",i+1);
print_arr(a,n);
}
}
void main()
{
printf("Enter the no of elements in the array : ");
scanf("%d",&n);
printf("Enter the elements\n");
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("The unsorted array is : ");
print_arr(a,n);
bubble_sort(a,n);
print_arr(a,n);
}