Advertisement
apl-mhd

bouble sort

Feb 6th, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5.  
  6.  
  7.  
  8. int main()
  9. {
  10.  
  11.  int x, i,j,n,temp, a[10000];
  12.  
  13.     clock_t start, stop;
  14.  
  15.  printf("Enter array size:");
  16.  
  17.  scanf("%d",&n);
  18.  
  19.     for(i=0; i<n;i++){
  20.  
  21.  
  22.         a[i] = rand() % 100+1;
  23.  
  24.     }
  25.  
  26.     start = clock();
  27.      for(i=1; i<n;i++){
  28.  
  29.         for(j = 0; j<n-i; j++){
  30.  
  31.             if(a[j+1] < a[j]){
  32.  
  33.                 temp = a[j];
  34.                 a[j] = a[j+1];
  35.                 a[j+1] = temp;
  36.             }
  37.         }
  38.  
  39.  
  40.     }
  41.  
  42.     stop =  clock();
  43.  
  44.     double timeCount = stop-start;
  45.  
  46.      for(i=0; i<n;i++){
  47.  
  48.  
  49.         printf(" %d ",a[i]);
  50.     }
  51.  
  52.     printf("time:%f\n", timeCount);
  53.  
  54.  
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement