rjcostales

quicksort.c

Feb 11th, 2021 (edited)
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.68 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <time.h>
  5. #include "fileutils.h"
  6.  
  7. static int compare(const void *a, const void *b)
  8. {
  9.     /* The pointers point to offsets into "array",
  10.         so we need to dereference them to get at the strings. */
  11.  
  12.     return strcmp(*(const char **) a, *(const char **) b);
  13. }
  14.  
  15. int main(int argc, char *argv[])
  16. {
  17.     str page[MAXSIZE];
  18.     int size = read(page);
  19.  
  20.     fprintf(stderr, "%s %d records\n", argv[0], size);
  21.  
  22.     clock_t start, end;
  23.     start = clock();
  24.  
  25.     qsort(page, size, sizeof(const char *), compare);
  26.  
  27.     end = clock();
  28.  
  29.     fprintf(stderr, "execution time: %0.6f secs.\n", ELAPSE_TIME(end - start));
  30.  
  31.     write(page);
  32.  
  33.     return 0;
  34. }
  35.  
Add Comment
Please, Sign In to add comment