Created
March 19, 2014 19:31
-
-
Save ionox0/9649459 to your computer and use it in GitHub Desktop.
searches a binary search tree for a range of values (see my arrayToBST class for testing)
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
function rangeSearchBST(bst, min, max){ | |
var list = []; | |
function searchTree(bst, min, max){ | |
if (bst){ | |
searchTree(bst.left, min, max); | |
if (min<bst.value & bst.value<max){ | |
list.push(bst.value); | |
} | |
searchTree(bst.right, min, max); | |
} | |
return list; | |
} | |
return searchTree(bst, min, max); | |
} | |
rangeSearchBST(arrayToBST(test), 1, 5); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment