/* File: demo8a.c * * Demonstrate binary search tree. * */ #include #include #include "bst.h" int main() { tnode *tree = NULL ; printf("\n\n### Simple test ###\n") ; printf("item [size]\n\n") ; tree = bst_insert(tree, 11) ; tree = bst_insert(tree, 3) ; tree = bst_insert(tree, 21) ; tree = bst_insert(tree, 9) ; tree = bst_insert(tree, 32) ; tree = bst_insert(tree, 1) ; tree = bst_insert(tree, 16) ; printf("\n-------------------------------\n") ; bst_walk(tree) ; printf("\n-------------------------------\n") ; // Testing bst_find() // tnode *ptr ; int n ; printf("\n\n### Testing bst_find() ###\n") ; n = 9 ; ptr = bst_find(tree, n) ; if (ptr != NULL) { printf("Found %d\n", ptr->data) ; } else { printf("Did not find %d\n", n) ; } n = 23 ; ptr = bst_find(tree, n) ; if (ptr != NULL) { printf("Found %d\n", ptr->data) ; } else { printf("Did not find %d\n", n) ; } // Testing bst_remove() // int found ; printf("\n\n### Testing bst_remove() ###\n") ; n = 11 ; tree = bst_remove(tree, n, &found) ; if (found) { printf("Found %d\n", n) ; } else { printf("Did not find %d\n", n) ; } printf("\n-------------------------------\n") ; bst_walk(tree) ; printf("\n-------------------------------\n") ; bst_destroy(tree) ; return 0 ; }