示例#1
0
int main() {
	char remove[2];
	remove[1] = 0;
	for(*remove='A'; *remove<'Z'; (*remove)++) {
		BOSTree *t = test_tree();
		bostree_remove(t, bostree_lookup(t, remove));
		test_tree_sanity(t);
		if(bostree_node_count(t) != ('Z' - 'A' - 1)) {
			printf("Removed one node from a tree, but the node count did not decrease properly.\n");
			exit(1);
		}
		bostree_destroy(t);
	}

	return 0;
}
示例#2
0
int main() {
	BOSTree *tree = bostree_new((BOSTree_cmp_function)strcmp, NULL);

	char iter;
	printf("Insert test:\n");
	for(iter='A'; iter<='Z'; iter++) {
		char *data = malloc(2);
		*data = iter;
		data[1] = 0;
		printf("Insert %s, ", data);
		bostree_insert(tree, data, strdup("Value"));

		test_tree_sanity(tree);
	}

#ifndef NDEBUG
	bostree_print(tree);
#endif


	printf("\nRemove test:\n");
	for(iter='A'; iter<='Z'; iter++) {
		char data[2];
		*data = iter;
		data[1] = 0;
		printf("Remove %s, ", data);
		BOSNode *node = bostree_lookup(tree, data);
		if(node != NULL) {
			free(node->key);
		}
		else {
			printf("Lookup for %s showed it was already deleted\n", data);
			exit(1);
		}
		bostree_remove(tree, node);

		test_tree_sanity(tree);
	}
	printf("\n");

	bostree_destroy(tree);
	exit(0);
}
示例#3
0
文件: bostree.c 项目: preed/pqiv
/*
	Free the memory used by a tree structure and all of its nodes.
*/
void bostree_destroy(BOSTree *tree) {
	while(tree->root_node != NULL) {
		bostree_remove(tree, bostree_select(tree, 0));
	}
	free(tree);
}