﻿ 二叉树的非递归遍历

# 1. 递归实现

### 先序

``````public void preOrder(){
preOrder(root);
}
private void preOrder(Node node){
if(node != null){
System.out.println(node.value);
preOrder(node.left);
preOrder(node.right);
}
}
``````

### 中序

``````public void midOrder(){
midOrder(root);
}
private void midOrder(Node node){
if(node != null){
midOrder(node.left);
System.out.println(node.value);
midOrder(node.right);
}
}
``````

### 后序

``````public void postOrder(){
postOrder(root);
}
private void postOrder(Node node){
if(node != null){
postOrder(node.left);
postOrder(node.right);
System.out.println(node.value);
}
}
``````

# 2. 非递归

### 前序

``````public void preOrderNew(){
preOrderNew(root);
}
private void preOrderNew(Node node){
if(node != null){

while(!list.isEmpty()){
Node temp = (Node) list.removeFirst();
if(temp.right != null){
}
if(temp.left != null){
}
System.out.println(temp.value);
}
}
}
``````

### 中序

``````public void midOrderNew(){
midOrderNew(root);
}
private void midOrderNew(Node node){
while(!list.isEmpty() || node != null){
if(node != null){
node = node.left;
}else{
node = list.removeFirst();
System.out.println(node.value);
node = node.right;
}
}
}
``````

### 后序

``````public void postOrderNew(){
postOrderNew(root);
}
private void postOrderNew(Node node){
if(node != null){

while(!list1.isEmpty()){
Node temp = list1.removeFirst();
if(temp.left != null){
}
if(temp.right != null){