二叉树的实现及先序、中序、后序遍历 (三)

2014-11-24 11:22:30 · 作者: · 浏览: 1

{
if(node.getLeftNode()!=null)
{
this.zhongIterator(node.getLeftNode());
}
this.printNode(node);
if(node.getRightNode()!=null)
{
this.zhongIterator(node.getRightNode());
}
}

/**后序遍历二叉树*/
public void houIterator(TreeNode node)
{
if(node.getLeftNode()!=null)
{
this.houIterator(node.getLeftNode());
}
if(node.getRightNode()!=null)
{
this.houIterator(node.getRightNode());
}
this.printNode(node);
}

public static void main(String[] args) {
BinaryTree binaryTree = new BinaryTree();
TreeNode node = binaryTree.init();
System.out.println("先序遍历的情况");
binaryTree.xianIterator(node);
System.out.println("\n中序遍历的情况");
binaryTree.zhongIterator(node);
System.out.println("\n后序遍历的情况");
binaryTree.houIterator(node);
}

}