Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- #include<windows.h>
- #define N 10000
- int a[N];
- void bubblesort(){
- int i, j, x;
- for(i=1; i<N; i++){
- for(j=N; j>=i; j--){
- if(a[j-1] > a[j]){
- x = a[j-1];
- a[j-1] = a[j];
- a[j] = x;
- }
- }
- }
- }
- double GetTime()
- {
- long long f,t;
- QueryPerformanceFrequency((PLARGE_INTEGER)&f);
- QueryPerformanceCounter((PLARGE_INTEGER)&t);
- return (double)t/(double)f;
- }
- int main(){
- int i;
- srand(time(NULL));
- for(i=0; i<N; i++) a[i] = rand()%100;
- double one=GetTime();
- bubblesort();
- double two=GetTime();
- printf("%lf", (double)(two-one));
- //for(i=0; i<N-1; i++) if( a[i] > a[i+1]){printf("NIEPOSORTOWANY"); break;}
- //for(i=0; i<N; i++) printf("[%d]: %d\t", i, a[i]);
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement