homework 6 submission

This doesn't make sense, because r never changes. What you really want here is either a loop that uses remove, OR a post-order traversal of the tree.