Created
July 10, 2016 00:21
-
-
Save danielrobertson/76c373b746725bdf9fd0a98de72833a5 to your computer and use it in GitHub Desktop.
Check is BST
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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