- 4
- 0
- 约1.22万字
- 约 13页
- 2016-12-06 发布于贵州
- 举报
JAVA二树递归和非递归遍历的用法
JAVA二叉树递归和非递归遍历的用法
1、递归遍历
[java]// 先序遍历(递归实现)------------------------------------------------------------- /* 1. Visit the node. 1. Call itself to traverse the node’s left subtree. 3. Call itself to traverse the node’s right subtree. 4. base case: there is no node */ private void preOrder(Node localRoot){ if(localRoot != null) { visit(localRoot); // System.out.print(localRoot.iData + ); preOrder(localRoot.leftChild); preOrder(localRoot.rightChild); } } // 中序遍历(递归实现)-------------
原创力文档

文档评论(0)