// The bubble sort. // This algorithm bubbles up largest repeatedly // and places it at positions i=n, n-1, ..., 2. // At i-th iteration a[i+1], ..., a[n] are sorted and // geater than or eqaul to a[1], ..., a[i]. // Movement of larger element to the right is like a bubble. #include #include int a[10000]; swap(i,j) int i,j; {int w; w=a[i]; a[i]=a[j]; a[j]=w; } main() { int i,j,n,t; printf("input size \n"); scanf("%d",&n); /*for (i=1;i<=n;i++) { scanf("%d",&a[i]);};*/ for (i=1;i<=n;i++) a[i]=random()%1000; t=clock(); for (i=n;i>=1;i--) for (j=2;j<=i;j++) if (a[j-1]>a[j])swap(j-1,j); /* swap a[j-1] and a[j] */ for (i=1;i<=10;i++) { printf("%d ",a[i]);} printf("\ntime= %d millisec\n",(clock()-t)/1000); }