2019.4.2
public void postorderUsingStack(){
postorderUsingStack(root);
}
private void postorderUsingStack(TreeNode<T> root){
if(root == null)
return;
Stack<TreeNode<T>> stack = new Stack<>();
TreeNode<T> current = root;
TreeNode<T> pre = null;
while(current != null){
stack.push(current);
current = current.left;
}
while(!stack.empty()){
current = stack.pop();
if(current.right != null && current.right != pre){
stack.push(current);
current = current.right;
while (current != null){
stack.push(current);
current = current.left;
}
}
else{
System.out.print(current.element+" ");
pre = current;
}
}
}
