https://blog.csdn.net/My_Jobs/article/details/43451187
https://blog.csdn.net/Monster_ii/article/details/82115772
后序遍历
import java.util.Stack; /** * public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; * * <p>public TreeNode(int val) { this.val = val; * * <p>} * * <p>} */ public class Solution { public void PrintFromTopToBottom(TreeNode root) { Stack<TreeNode> s = new Stack<>(); TreeNode cur = root; TreeNode last = null; while(cur != null || !s.empty()){ if(cur != null){ s.push(cur); cur = cur.left; }else{ TreeNode top = s.peek(); if(top.right == null || top.right == last){ s.pop(); System.out.print(top.val); last = top; }else{ cur = top.right; } } } } }