package muyanmoyang.data.BTree;
/**
* 二叉树的节点
* @author hadoop
*
*/
class BtNode {
String data ;
BtNode lchild ;
BtNode rchild ;
public BtNode(String data, BtNode lchild, BtNode rchild) {
super();
this.data = data;
this.lchild = lchild;
this.rchild = rchild;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
public BtNode getLchild() {
return lchild;
}
public void setLchild(BtNode lchild) {
this.lchild = lchild;
}
public BtNode getRchild() {
return rchild;
}
public void setRchild(BtNode rchild) {
this.rchild = rchild;
}
}
<pre name="code" class="java">package muyanmoyang.data.BTree;
import java.awt.List;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.Stack;
public class BTree {
static BtNode root = initTree() ;
public static void main(String[] args) {
//初始化
BtNode bt = initTree() ;
//先序遍历二叉树
System.out.print("\n先序遍历:");
preOrder(bt) ; // 先序遍历
System.out.print("\n先序遍历(非递归):");
preOrderWithoutRecursion(bt) ; // 先序遍历(非递归)
System.out.print("\n中序遍历:");
inOrderWithoutRecursion(bt); // 中序遍历
System.out.print("\n后序遍历:");
postOrder(b