In the morris traversal of a binary tree, it uses every right leaf node to build the connection towards the current node.
Suppose we are traversing the tree in the preorder way, when reaching the leaf nodes, how can we judge if we meet the leaf nodes?
eg. we cannot use the following line to check: if (null == node.left && null == node.right)
because here node.right is pointing to the current node because of the morris algorithm.
One good way is that we always mark the nodes visited as visited, using a field in the TreeNode object, but what if we do not have this field, as in many cases?
Anyone has the idea how to check if you reach leaf nodes? Thanks.
Regards, Jack