-
- public void inorder() {
- System.out.print("binaryTree递归中序遍历:");
- inorderTraverseRecursion(root);
- System.out.println();
- }
-
-
- public void layerorder() {
- System.out.print("binaryTree层次遍历:");
- LinkedList<Node<Integer>> queue = new LinkedList<Node<Integer>>();
- queue.addLast(root);
- Node<Integer> current = null;
- while(!queue.isEmpty()) {
- current = queue.removeFirst();
- if (current.getLeftChild() != null)
- queue.addLast(current.getLeftChild());
- if (current.getRightChild() != null)
- queue.addLast(current.getRightChild());
- System.out.print(current.getValue());
- }
- System.out.println();
- }
-
-
-
- public int getDepth() {
- return getDepthRecursion(root);
- }
-
- private int getDepthRecursion(Node<Integer> node){
- if (node == null)
- return 0;
- int llen = getDepthRecursion(node.getLeftChild());
- int rlen = getDepthRecursion(node.getRightChild());
- int maxlen = Math.max(llen, rlen);
- return maxlen + 1;
- }
-
- public void preorder() {
- System.out.print("binaryTree递归先序遍历:");
- preorderTraverseRecursion(root);
- System.out.println();
- }
-
-
java 二叉树递归遍历算法
原文:http://www.cnblogs.com/kisty/p/4918124.html