Advertisement
patryk

Untitled

Mar 20th, 2014
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.88 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<windows.h>
  4.  
  5. #define N 10000
  6.  
  7. int a[N];
  8.  
  9. void bubblesort(){
  10.     int i, j, x;
  11.     for(i=1; i<N; i++){
  12.         for(j=N; j>=i; j--){
  13.             if(a[j-1] > a[j]){
  14.                 x = a[j-1];
  15.                 a[j-1] = a[j];
  16.                 a[j] = x;
  17.             }
  18.         }
  19.     }
  20.  
  21. }
  22.  
  23. double GetTime()
  24. {
  25.   long long f,t;
  26.   QueryPerformanceFrequency((PLARGE_INTEGER)&f);
  27.   QueryPerformanceCounter((PLARGE_INTEGER)&t);
  28.   return (double)t/(double)f;
  29. }
  30.  
  31. int main(){
  32.  
  33.     int i;
  34.  
  35.     srand(time(NULL));
  36.     for(i=0; i<N; i++) a[i] = rand()%100;
  37.  
  38.     double one=GetTime();
  39.     bubblesort();
  40.     double two=GetTime();
  41.  
  42.     printf("%lf", (double)(two-one));
  43.  
  44.     //for(i=0; i<N-1; i++) if( a[i] > a[i+1]){printf("NIEPOSORTOWANY"); break;}
  45.     //for(i=0; i<N; i++) printf("[%d]: %d\t", i, a[i]);
  46.  
  47.     getch();
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement