Make delicious recipes!

Populate In-Order successor in each node


Successor means next element obtained when we traverse.

So, if we keep a pointer to previously visited node, then current node is the successor.


Assuming every node has an element called successor, the code is as follows:


“prev” is a global variable here.

Can be made a function argument if desired.


Similarly, to populate any successor, we can just traverse the tree, keep a previous pointer and set that previous’ successor to the current element.

Another approach to do the same is to traverse in reverse order and set current’s successor as previous.




Like us on Facebook to remain in touch
with the latest in technology and tutorials!


Got a thought to share or found a
bug in the code?
We'd love to hear from you:

Name:
Email: (Your email is not shared with anybody)
Comment:

Facebook comments:

Site Owner: Sachin Goyal