So I have a helper function that is supposed to print out the internal nodes and leaves of a binary tree (unsorted). I won't provide the code since I'm in a class, but I can tell you that I have coded it up and it works for the first node I throw in there:
def helper(root, internals=[], leaves=[]):
#function code here...
>>> helper(node)
([13, 14, 27], [10, 11, 12, 17, 19])
which is the correct output, as far as I know. However, when I call the same function again on another node, the output is overwritten into the previous one:
>>> helper(pen)
([13, 14, 27, 6, 8, 14], [10, 11, 12, 17, 19, 2, 4, 10, 12])
which is incorrect, since the tree pen
does not have the elements 13,14,27 or 10,11,12,17,19. Can someone explain what's going on here? I have to test my function for different cases without restarting the shell every single time. How do I fix this?