My code at the moment allows me to search for a specific node, I would like to edit it so that I can search within a range of numbers. For example, I have a price list of apples, and I would like to add all apples to a list/dictionary that cost between $2-$4 or something like that.
Here is my current code
def valueOf(self, key):
node = self._bstSearch(self._root, key)
assert node is not None, "Invalid map key."
return node.value
def _bstSearch(self, subtree, target):
if subtree is None:
return None
elif target < subtree.key:
return self._bstSearch( subtree.left, target)
elif target > subtree.key:
return self._bstSearch(subtree.right, target)
else:
return subtree
I think I should be editing target to change it from a single item search to a ranged item search but I'm not 100% sure how to