Advertisement
iampiergiu

test

Nov 7th, 2011
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.78 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #include <stdlib.h>
  4.  
  5. #include <time.h>
  6.  
  7. #include <unistd.h>
  8.  
  9.  
  10.  
  11. #define NUMEL 2000000
  12.  
  13.  
  14.  
  15. int compare (const void * a, const void * b)
  16.  
  17. {
  18.  
  19.   return ( *(int*)a - *(int*)b );
  20.  
  21. }
  22.  
  23.  
  24.  
  25. int main ()
  26.  
  27. {
  28.  
  29.   int values[NUMEL];
  30.  
  31.   int i=0;
  32.  
  33.   time_t inizio,fine;
  34.  
  35.  
  36.  
  37.   /*lettura*/
  38.  
  39.   time (&inizio);
  40.  
  41.   FILE *file = fopen ( "numbers.txt", "r" );  
  42.  
  43.  
  44.  
  45.   while(feof(file)==0 && i<=(NUMEL-1) )
  46.  
  47.     fscanf(file,"%d\n",&values[i++]);
  48.  
  49.  
  50.  
  51.   fclose ( file );
  52.  
  53.   time (&fine);
  54.  
  55.   printf ("tempo di lettura: %f \n",difftime(fine, inizio));
  56.  
  57.  
  58.  
  59.   /*sort*/
  60.  
  61.   time (&inizio);
  62.  
  63.   qsort (values, NUMEL, sizeof(int), compare);
  64.  
  65.   time (&fine);
  66.  
  67.  
  68.  
  69.  
  70.  
  71.   printf ("tempo di sort: %f \n",difftime(fine, inizio));
  72.  
  73.   return 0;
  74.  
  75. }
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement