1: #include<stdio.h>
2: #include<conio.h>
3: void main()
4: {
5: void sort(int a[25], int n);
6: int a[25], n, i;
7: clrscr();
8: printf("Enter the number of elements : ");
9: scanf("%d", &n);
10: printf("\n\nEnter the elements :\n\n\n");
11: for(i=0;i<n;i++)
12: scanf("%d", &a[i]);
13: sort(a,n);
14: getch();
15: }
16: void sort(int a[25], int n)
17: {
18: int i, j, temp,d;
19: clrscr();
20: for(i=0;i<n-1;i++)
21: {
22: for(j=0;j<n-i-1;j++)
23: {
24: if(a[j]>a[j+1])
25: {
26: temp=a[j];
27: a[j]=a[j+1];
28: a[j+1]=temp;
29: }
30: }
31: ` if(i<n-2)
32: {
33: printf("\n\n\t\tSorted array after scan %d\n\n\t", i+1);
34: for(d=0;d<n;d++)
35: printf("%d\t", a[d]);
36: }
37: }
38: printf("\n\n\t\tSorted array\n\n\t");
39: for(i=0;i<n;i++)
40: printf("%d\t", a[i]);
41: }
Bubble Sort
Subscribe to:
Posts (Atom)
No comments:
Post a Comment