int main(void) { struct node *bst = create_good_bst(); printf("==1st==\n"); traverse_bst(bst); printf("%s\n", (is_bst(bst) ? "good" : "bad") ); bst = create_bad_bst(); printf("==2nd==\n"); traverse_bst(bst); printf("%s\n", (is_bst(bst) ? "good" : "bad") ); return 0; }
// in-order traversal (it should be ordered) int traverse_bst(struct node *root) { if (root == NULL) return 1; traverse_bst(root->left); if (root->data > prev) { printf("false\n"); //exit(255); } printf("%d\n", root->data); prev = root->data; traverse_bst(root->right); }
int main() { int input_arr[] = {12,4,34,6,8,2,14,23}; int i = 0; bst_node *root = NULL; for(i=0;i<=7;i++) { make_bst(&root,input_arr[i]); } printf("\n"); traverse_bst(root); printf("\n"); }