Skip to content

Instantly share code, notes, and snippets.

@ionox0
Created March 19, 2014 19:31
Show Gist options
  • Save ionox0/9649459 to your computer and use it in GitHub Desktop.
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)
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