I'm trying to write a code that traverses
a general tree height by height from the root
of the tree. What I'm trying to write is something that prints a list
where the root is at index[0]
followed by the children
of the root and then their children. I'm trying to write it so it repeats this process for each subtree
until it reaches the bottom of the tree.
This is the design code that I have but I can't figure out how to write it in python.
def traversal(tree):
if tree is empty:
print("No tree to traverse")
else:
starting at the root print a list containing the root at [0], its
children, and its grand children
recursively call function
set new root to child of root
traverse each subtree until bottom of tree