1 #include "lib.h" 2 #include "allocate.h" 3 #include <stdio.h> 4 #include <stdlib.h> 5 6 static int 7 int_cmp (const void *_a, const void *_b) 8 { 9 const int *a = _a; 10 const int *b = _b; 11 return *a - *b; 12 } 13 14 #define MIN(_x,_y) ((_x) < (_y) ? (_x) : (_y)) 15 16 int 17 main (int argc, char **argv) 18 { 19 struct ptr_list *l = NULL, *l2; 20 int i, *e; 21 const int N = argv[1] ? atoi (argv[1]) : 10000; 22 23 srand (N); 24 for (i = 0; i < 1000; i++) 25 (void)rand (); 26 27 for (i = 0; i < N; i++) { 28 e = (int *)malloc (sizeof (int)); 29 *e = rand (); 30 add_ptr_list (&l, e); 31 } 32 sort_list (&l, int_cmp); 33 // Sort already sorted stuff. 34 sort_list (&l, int_cmp); 35 36 l2 = l; 37 do { 38 l2->nr = MIN (l2->nr, rand () % 3); 39 for (i = 0; i < l2->nr; i++) 40 *((int *)(l2->list[i])) = rand(); 41 l2 = l2->next; 42 } while (l2 != l); 43 sort_list (&l, int_cmp); 44 45 return 0; 46 } 47