You are viewing a single comment's thread. Return to all comments →
Morris Traversal without using Recursion & Stack
Node pre; if(root == null) return; Node curr = root; while(curr != null){ if(curr.left == null){ System.out.print(curr.data+" "); curr = curr.right; }else{ pre = curr.left; while(pre.right !=null && pre.right != curr) pre = pre.right; if(pre.right == null){ pre.right = curr; System.out.print(curr.data+" "); curr = curr.left; }else{ pre.right=null; curr=curr.right; } } }
Seems like cookies are disabled on this browser, please enable them to open this website
Tree: Preorder Traversal
You are viewing a single comment's thread. Return to all comments →
Morris Traversal without using Recursion & Stack