You are viewing a single comment's thread. Return to all comments →
** java iterative solution using stack**
public static void preOrder(Node root) {
Stack<Node> s = new Stack<Node>(); Node curr = root; if(curr==null){ return; } while(curr!=null||s.size()>0){ while(curr!=null){ s.push(curr); System.out.print(curr.data+" "); curr=curr.left; } curr= s.pop(); 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 →
** java iterative solution using stack**
public static void preOrder(Node root) {