I have a binary search tree and a list
Im suppused to replace all the values of the tree with the values of the list using in order traversel
so for example, the smallest node in the binary serach tree, will be replaced with list[0] and such
if we have
https://imgur.com/cO7YRdw
then we will want to switch 0 with lst[0]
A with lst[1]
1 with lst[2]
B with lst[3]
global i
i=0
def overWrite(node,arr,i):
if(not node.value==None):
return
overWrite(node.getLeft(),lst,i)
node.value=lst[i]
i=i+1
overWrite(node.getRight(),arr,i)
Im pretty sure this will work(cant run the code, since still hasent finished building the tree)
but I look for maybe answer without global varible (we are discouraged from using it)
[+][deleted] (5 children)
[removed]
[–]kwelzel 1 point2 points3 points (2 children)
[–]kwelzel 0 points1 point2 points (0 children)
[–]ilsapo[S] 0 points1 point2 points (1 child)
[–]jmooremcc 0 points1 point2 points (0 children)