中序

二叉树的递归,非递归遍历,深度优先遍历,广度优先遍历

馋奶兔 提交于 2020-03-01 03:57:10
/** * 二叉树的定义和遍历 */ public class BinaryTree { /** * 打印节点的信息 */ public void printNode(TreeNode<String> node){ System.out.print(node.getData()+" "); } /** * 递归先序遍历二叉树 */ public void preIterator(TreeNode<String> node){ this.printNode(node); if (node.getLefNode() != null) { this.preIterator(node.getLefNode()); } if (node.getRigNode() != null) { this.preIterator(node.getRigNode()); } } /** * 递归中序遍历二叉树 */ public void midIterator(TreeNode<String> node){ if (node.getLefNode() != null) { midIterator(node.getLefNode()); } this.printNode(node); if (node.getRigNode() != null) { midIterator(node.getRigNode(