二叉树遍历(前序、中序、后序、层次遍历、深度优先、广度优先)

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;
       }
     }

   }
  }

  }
原文地址:https://www.cnblogs.com/tonggc1668/p/11984404.html