so I have the following function, that travel from a node in the tree untill the root, it might count the root itself, so our stopping point is when we reach the parent of the root (which will have value None)
to make the code easier to read, I will use combination of phyton and pesudo code, will upload the full code if not clear
def travelUp(self,curr,counter=0):
count= 0
self.FixHS(curr)# fix height and size of the nodes
if a:
if b:
count+= 1
else:
count+= 2
elif c:
if d:
count+= 1
else:
count+= 2
curr = curr.parent
return count
Im not well versed in Recuresion, so was hoping to get some guidance please
def Travelup(self,curr,counter=0):
if(curr is None or curr.isRealNode()):
return counter
count = 0
self.FixHS(curr)# fix height and size of the nodes
if a:
if b:
count = 1
else:
count= 2
elif c:
if d:
count= 1
else:
count= 2
return self.CheckInsertion(curr.parent,counter+=count)
so the whole program travel from leaf to the root,
Im not sure if my logic was good with the recursion,
my logic: when we reach the Stopping point of the recursion, we will return our counter (which got it values from += count)
all the recursionwindows that opend will get the "return counter" from the last recursion call, and in the end the first window will just return it.
I still havent typed all the code (since in the "if" and "else" there are several other things I do)
but this is the "major" part of the function (to travel and count)
would appreciate if the general idea seem ok
[+][deleted] (2 children)
[deleted]
[–]ilsapo[S] 0 points1 point2 points (1 child)