Ejemplo n.º 1
0
int main(void) {
  const unsigned max_size = 1000;
  unsigned graph[max_size][2];

  struct timeval tv;
  if (gettimeofday(&tv, NULL)) {
    return 1;
  }
  unsigned long long t = (unsigned long long)tv.tv_sec * 1000000 + tv.tv_usec;
  const int seed = (t >> 32) ^ t;

  srand(seed);
  unsigned size = rand() % max_size + 1;
  for (unsigned i = 0; i < size; ++i) {
    graph[i][0] = rand() % (size+1);
    graph[i][1] = rand() % (size+1);
  }

  struct node n1[max_size], n2[max_size];
  make_graph(size, graph, n1);
  make_graph(size, graph, n2);

  schorr_waite(n1);
  simple_traverse(n2);

  for (unsigned i = 0; i < size; ++i) {
    if (graph[i][0] == size) {
      assert(n1[i].l == NULL);
      assert(n2[i].l == NULL);
    } else {
      assert(n1[i].l == n1 + graph[i][0]);
      assert(n2[i].l == n2 + graph[i][0]);
    }
    if (graph[i][1] == size) {
      assert(n1[i].r == NULL);
      assert(n2[i].r == NULL);
    } else {
      assert(n1[i].r == n1 + graph[i][1]);
      assert(n2[i].r == n2 + graph[i][1]);
    }
    assert(n1[i].m == n2[i].m);
  }

  return 0;
}
Ejemplo n.º 2
0
void main(int argc, char **argv)
{
	int numnodes = atoi(argv[1]);
	unsigned int seed  = atoi(argv[2]);
	int i = 1;
	struct node * root = makeNode();
	while (i < numnodes) {
		struct node * n = root;
		struct node * p = 0;
		int j = 0;
		while (n) {
			j = rand() % 2;
			p = n;
			if (j) n = n->l;
			else n = n->r;
		}
		if (j) p->l = makeNode();
		else p->r = makeNode();
		i++;
	}
	schorr_waite(root);
}