We're given a binary tree with inorder threads. Meaning, if a node does not have a left child (right child), left threads (right threads) are linked from that node to its inorder predecessor (inorder successor).
Can you help me come up with pseudocode or algorithm that would find a node's parent? For example (see photo below), the given node is Q, the parent must be I. (We are supposed to make use of the given idea that the binary is inorder threaded)
TMI: I actually need this pseudocode/algorithm in creating another algorithm that would get the postorder successor of a binary tree.

From the picture it seems that:
headnode is a special sentinel node that just serves as sentinel node for attaching the actual tree (which could be empty)Then the logic for finding the parent of a given node can be as follows:
Here is an implementation of that idea in JavaScript. This code snippet defines a
Nodeclass. It creates the tree given in the example. TheNodeclass has aninorderiterator which we use to visit each node and then display its parent using the above algorithm: