Reputation: 697
I see where how it goes down the tree, but don't see how it traverses back up and onto the right side of the root. Can someone explain? This is fully functional inorder traversal code in Python.
def inorder(self):
if self:
if self.leftChild:
self.leftChild.inorder()
print(str(self.value))
if self.rightChild:
self.rightChild.inorder()
Where in this code specifically does it go back in the tree?
Upvotes: 0
Views: 118
Reputation:
Reaching the end of a function is the same thing as executing return
which is the same thing as executing return None
.
For functions that do not return a meaningful value, it is preferred to let execution reach the end of the function rather than place a superfluous return
at the end of the function.
Upvotes: 1