Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/time.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #define MAX 65536
- int main(int argc, char**argv)
- {
- double start;
- struct timeval tm;
- double duration; // gibt die Laufzeit
- int k,i,x,tmp,a[MAX];
- unsigned int seed;
- FILE* urandom = fopen("/dev/urandom", "r");
- for(i=0;i<MAX;i++)
- {
- fread(&seed, sizeof(int), 1, urandom);
- a[i] = seed;
- }
- fclose(urandom);
- gettimeofday(&tm,NULL);
- start = (double) (tm.tv_sec) + ((double) (tm.tv_usec))/1.0e6;
- for(k=0;k<MAX-1;k++)
- {
- i=k;
- for(x=(k+1);x<MAX;x++)
- {
- if(a[x] < a[i])
- i = x;
- }
- tmp = a[i];
- a[i] = a[k];
- a[k] = tmp;
- }
- gettimeofday(&tm,NULL);
- duration = (double) (tm.tv_sec) + ((double) (tm.tv_usec))/1.0e6 - start;
- for(i=0;i<MAX;i++)
- {
- printf("%d\n",a[i]);
- }
- printf("\nLaufzeit: %lf\n",duration);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement