You are viewing a single comment's thread. Return to all comments →
Same solution with java:
public static void preOrder(Node root) { if(root == null ) return ; Node pre; Node curr = root; while(curr!=null){ if(curr.left == null){ System.out.print(curr.data+" "); curr=curr.right; continue; } 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{ 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 →
Same solution with java: