Threaded Binary Tree - Non Recursive Inorder Traversal For A Threaded Binary Tree

Non Recursive Inorder Traversal For A Threaded Binary Tree

As this is a non-recursive method for traversal, it has to be an iterative procedure; meaning, all the steps for the traversal of a node have to be under a loop so that the same can be applied to all the nodes in the tree. We will consider the INORDER traversal again. Here, for every node, we'll visit the left sub-tree (if it exists) first (if and only if we haven't visited it earlier); then we visit (i.e. print its value, in our case) the node itself and then the right sub-tree (if it exists). If the right sub-tree is not there, we check for the threaded link and make the threaded node the current node in consideration. Please, follow the example given below.

Read more about this topic:  Threaded Binary Tree

Famous quotes containing the words threaded and/or tree:

    Two children, all alone and no one by,
    Holding their tattered frocks, thro’an airy maze
    Of motion lightly threaded with nimble feet
    Dance sedately; face to face they gaze,
    Their eyes shining, grave with a perfect pleasure.
    Laurence Binyon (1869–1943)

    What signify a few lives lost in a century or two? The tree of liberty must be refreshed from time to time with the blood of patriots and tyrants. It is its natural manure.
    Thomas Jefferson (1743–1826)