I currently have a binary search tree consisting of a key being a number and a value assigned to that key. I am to find a function that take in 2 input from user (min and max) such that the it returns a dictionary where keys are those numbers that the keys in binary search tree falls in. My code so far is like so:
(players is the BST players.root is the starting for BST)
def getPlayersInRange(min, max, players,current,dic):
if current==None or current.key>max:
return dic
elif(current.key>=min and current.key<=max):
dic[current.key]=current.value
if current.right!=None:
getPlayersInRange(min,max,players,current.right,dic)
if current.left!=None:
getPlayersInRange(min,max,players,current.left,dic)
Result = getPlayersInRange(min, max, players,dic={},current=players.root)
The problem that I am running into now is that I am unable to get the dic value back as it is lost but i also cant use return as only current.right will be called and not the left side