In Postorder traversal, we visit nodes in Left - Right - Node (LRN) order, which means each node is visited only after its left and right subtrees. Implementing this directly with Morris Traversal is tricky because we need to know when both subtrees are fully visited. To simplify, we use a mirrored Preorder approach: traverse the tree in Node - Right - Left (NRL) order, visiting each node when we first encounter it, then moving to the right subtree, and finally to the left subtree. During this traversal, we store the nodes in an array. Finally, by reversing the array, the NRL order becomes LRN, giving the correct Postorder sequence.
Morris Postorder Traversal Steps
Start with root Node(curr) and for each node:
If the node does not have a right child, visit(store) the node and move to the left child.
If the node has a right child, find the leftmost node in the right subtree.
If the leftmost node’s left is NULL. Make the current node as the left child of this leftmost node (temporary link).Visit (store) the current node and move to the right child.
If the leftmost node’s left points to the current node. Remove the temporary link (leftmost->left = NULL) and move to the left child.
Repeat until curr == NULL.
After traversal, reverse the stored array. This converts Node-Right-Left (NRL) order into Left-Right-Node (LRN) postorder.