Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

inorder traversal - iterative method

void inOrder(struct Tree *root) {
    stack<Tree *> s;
    Tree *curr = root;
    while (curr != NULL || s.empty() == false)
    {
        while (curr !=  NULL)
        {
            s.push(curr);
            curr = curr->left;
        }
        cout << s.top()->data << " ";
        curr = s.top()->right;
        s.pop();
    } 
}
Source by www.interviewbit.com #
 
PREVIOUS NEXT
Tagged: #inorder #traversal #iterative #method
ADD COMMENT
Topic
Name
4+5 =