A root-to-leaf path in a tree is defined to be a sequence of nodes starting from the root node and proceeding downwards to a leaf.
Required that given a tree, output the tree after reversing all root-to-leaf paths.
For the following tree:
root = 5
root.right = 8, root.left = 4
root.right.right = 4, root.right.left = 13, root.left.left = 11
root.right.left.right = 1, root.left.left.right = 2, root.left.left.left = 7
The output tree is:
root = 4
root.right = 13, root.left = 4
root.right.right = 1, root.right.left = 8, root.left.left = 11
root.right.left.right = 2, root.left.left.right = 7, root.left.left.left = 5
I think it would be useful to use linked lists to store the paths, but the code I wrote doesn't work and I don't know what its problem is.
Thanks in advance.