Skip to content

Instantly share code, notes, and snippets.

@danielrobertson
Created July 10, 2016 00:21
Show Gist options
  • Save danielrobertson/76c373b746725bdf9fd0a98de72833a5 to your computer and use it in GitHub Desktop.
Save danielrobertson/76c373b746725bdf9fd0a98de72833a5 to your computer and use it in GitHub Desktop.
Check is BST
// Determine if a binary tree is a binary search tree
boolean isBst(Node r) {
return isBst(r, null, null);
}
boolean isBst(Node r, Integer min, Integer max) {
if(r == null)
return true;
if((min != null && r.data < min) || (max != null && r.data > max))
return false;
return isBst(r.left, min, r.data) && isBst(r.right, r.data, max);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment