int is_bst_helper(tree *root, int lower, int upper) { if (root == NULL) { return 1; } else if (root->value < lower || root->value > upper) { return 0; } return is_bst_helper(root->left, lower, root->value) && is_bst_helper(root->right, root->value, upper); }
int is_bst_helper(tree_t* t,tree_node_t* v,void* l,void* r){ if(v==NULL){ return 1; } int a,b; if(l==NULL || t->comparator(v->data,l)>0{ a =1; } if(r==NULL || t->comparator(v->data,r)<0){ b = 1; } return (a && b && is_bst_helper(t,v->left,l,v->data) && is_bst_helper(t,v->right,v->data,r)); }
int is_bst(tree_t* t){ return is_bst_helper(t,t->root,NULL,NULL); }
int is_bst(tree *root) { return is_bst_helper(root, INT_MIN, INT_MAX); }