Advertisement
rjcostales

quicksort.c

Jul 22nd, 2023
976
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.75 KB | None | 0 0
  1. /*
  2.  * C Program To Sort array in ascending order using Quicksort.
  3.  */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <time.h>
  8.  
  9. #define SIZE 50000
  10.  
  11. static int compare(const void *a, const void *b)
  12. {
  13.     /* The pointers point to offsets into "array",
  14.        so we need to dereference them to get at the strings. */
  15.  
  16.     return strcmp(*(const char **) a, *(const char **) b);
  17. }
  18.  
  19. int main(int argc, char *argv[])
  20. {
  21.     str     page[SIZE];
  22.     int     size = read(page);
  23.  
  24.    // create an array of random ints
  25.    srand(time(NULL));
  26.    for (int i = 0; i < SIZE; i++) array[i] = rand();
  27.  
  28.     qsort(page, size, sizeof(const char *), compare);
  29.  
  30.    // output array
  31.    for (int i = 0; i < SIZE; i++) printf("%i\n", array[i]);
  32.  
  33.    return 0;
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement