/* Test deleting nodes from the tree and making copies of it. */ for (i = 0; i < n; i++) { int *deleted; if (verbosity >= 2) printf (" Deleting %d...\n", delete[i]); deleted = bst_delete (tree, &delete[i]); if (deleted == NULL || *deleted != delete[i]) { okay = 0; if (deleted == NULL) printf (" Deletion failed.\n"); else printf (" Wrong node %d returned.\n", *deleted); } if (verbosity >= 3) print_whole_tree (tree, " Afterward"); if (!verify_tree (tree, delete + i + 1, n - i - 1)) return 0; if (verbosity >= 2) printf (" Copying tree and comparing...\n"); /* Copy the tree and make sure it's identical. */ { struct bst_table *copy = bst_copy (tree, NULL, NULL, NULL); if (copy == NULL) { if (verbosity >= 0) printf (" Out of memory in copy\n"); bst_destroy (tree, NULL); return 1; } okay &= compare_trees (tree->bst_root, copy->bst_root); bst_destroy (copy, NULL); } }