Advertisement
anechka_ne_plach

plachu

Feb 8th, 2022
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.60 KB | None | 0 0
  1. #include <inttypes.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <stdio.h>
  5.  
  6. typedef struct data {
  7.     int (*get_rank)(const struct data*);
  8.     char secret[];
  9. } data;
  10.  
  11. int get_rank(const data* d) {
  12.     return (d->secret[0]);
  13. }
  14.  
  15. int strcmp(const void * x1, const void * x2)
  16. {
  17.     data* t1 = (data*)x1;
  18.     data* t2 = (data*)x2;
  19.     return ( t1->get_rank(t1) - t2->get_rank(t2));              
  20. }
  21.  
  22. typedef int (*comparator_t)(const void *, const void *);
  23.  
  24. comparator_t comp = strcmp;
  25.  
  26. void rank_sort(data* elements[], size_t size) {
  27.     qsort(elements, size, sizeof(data*), comp);
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement