aboutsummaryrefslogtreecommitdiff
blob: d0ffb670cc0c475620ca56d73e57347591cb8375 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "lib.h"
#include "allocate.h"
#include <stdio.h>
#include <stdlib.h>

static int
int_cmp (const void *_a, const void *_b)
{
  const int *a = _a;
  const int *b = _b;
  return *a - *b;
}

#define MIN(_x,_y) ((_x) < (_y) ? (_x) : (_y))

int
main (int argc, char **argv)
{
  struct ptr_list *l = NULL, *l2;
  int i, *e;
  const int N = argv[1] ? atoi (argv[1]) : 10000;

  srand (N);
  for (i = 0; i < 1000; i++)
    (void)rand ();

  for (i = 0; i < N; i++) {
    e = (int *)malloc (sizeof (int));
    *e = rand ();
    add_ptr_list (&l, e);
  }
  sort_list (&l, int_cmp);
  // Sort already sorted stuff.
  sort_list (&l, int_cmp);

  l2 = l;
  do {
    l2->nr = MIN (l2->nr, rand () % 3);
    for (i = 0; i < l2->nr; i++)
      *((int*)(l2->list[i])) = rand();
    l2 = l2->next;
  } while (l2 != l);
  sort_list (&l, int_cmp);

  return 0;
}