Skip to content

Instantly share code, notes, and snippets.

anonymous
anonymous / is_binary_search_tree
Created December 18, 2012 08:48
Is a given tree a binary search tree
int is_binary_search_tree(struct node *n) {
return is_bst(n, INT_MIN, INT_MAX);
}
int is_bst(struct node *n, int min, int max) {
return !n || (n >= min && n < max) && is_bst(n->left, min, n->val) && is_bst(n->right, n->val, max);
}