We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
voidpostOrder(Noderoot){Nodet=root;Deque<Node>stack=newArrayDeque<Node>();stack.push(root);while(!stack.isEmpty()&&root!=null){root=stack.peek();//nodes without children should be printed if((root.left==null&&root.right==null)||(t==root.left||t==root.right)){//or nodes whose children have already been printed System.out.print(root.data+" ");stack.pop();t=root;}else{if(root.right!=null)stack.push(root.right);if(root.left!=null)stack.push(root.left);}}}
Tree: Postorder Traversal
You are viewing a single comment's thread. Return to all comments →
My Java solution without recursion