You are viewing a single comment's thread. Return to all comments →
Morris Traversal ## Complexity => Time :: O(n) | Space :: O(1)
void inOrder(Node root) { 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; curr = curr.left; }else{ pre.right=null; System.out.print(curr.data+" "); curr=curr.right; } } } }
Seems like cookies are disabled on this browser, please enable them to open this website
Tree: Inorder Traversal
You are viewing a single comment's thread. Return to all comments →
Morris Traversal ## Complexity => Time :: O(n) | Space :: O(1)