-
后序遍历:左右根,从叶子结点开始
//递归 public static void postOrder(TreeNode root){ if(root != null){ postOrder(root.lchild); postOrder(root.rchild); System.out.println(root.data + " "); } }
//后序遍历---非递归 public List<TreeNode> postOrder(TreeNode root){ while(root!=null || !stack.isEmpty()){ while(root!=null){ list.add(root); static.push(root); root = root.right; } TreeNode node = stack.pop(); root = node.left; } Conlections.reverse(list); return list; }