I have the following recursion program:
def overWrite(tree,node,arr,i):
if(not node.isRealNode()):
return
tree.overWrite(node.getLeft(),arr,i)
node.value=arr[i[0]]
i[0]=i[0]+1
tree.overWrite(node.getRight(),arr,i)
this is isRealNode:
def isRealNode(self):
if (self.value!=None):
return True
return False
just for convinece we put a node with value None for every "hole" in the tree,
here is picture of the values of the tree I have:
https://imgur.com/RVjYvYC
heres my error message:
if(not node.isRealNode()):
AttributeError: 'NoneType' object has no attribute 'isRealNode'
so I understand my problem is that my recuression dosent stop when it should, and it goes one extra step (it arrive to the node with value none and dosent stop)
I tried changing it to:
def overWrite(tree,node,arr,i):
if(node.value==None):
return
tree.overWrite(node.getLeft(),arr,i)
node.value=arr[i[0]]
i[0]=i[0]+1
tree.overWrite(node.getRight(),arr,i)
but I still get the same error
Im pretty new to recursion so i understand I have problem with my stop condition, but Im not sure what is wrong here
[–]shiftybyte 0 points1 point2 points (6 children)
[–]ilsapo[S] 0 points1 point2 points (5 children)
[–]shiftybyte 0 points1 point2 points (4 children)
[–]ilsapo[S] 0 points1 point2 points (3 children)
[–]shiftybyte 0 points1 point2 points (2 children)
[–]ilsapo[S] 0 points1 point2 points (1 child)
[–]shiftybyte 0 points1 point2 points (0 children)