二叉排序树,二叉树的中序,先序,后序遍历
来源:互联网 发布:揭秘网络赚钱的门道 编辑:程序博客网 时间:2024/06/07 11:33
public class BinaryTree {public static void main(String[] args) {int[] data = new int[10];for(int i = 0; i < data.length; i++) {data[i] = (int)(Math.random() * 100) + 1;System.out.print(data[i] + " ");}System.out.println();Node root = new Node();root.value = data[0];for(int i = 1; i < data.length; i++) {root.store(data[i]);}root.find(data[7]);System.out.println();System.out.println("----------------");root.find(23);System.out.println();System.out.println("----------------");root.preSearch();System.out.println();System.out.println("----------------");root.midSearch();System.out.println();System.out.println("----------------");root.afterSearch();System.out.println();System.out.println("----------------");}}class Node {int value;Node left;Node right;public void store(int value) {if(value < this.value) {if(left == null) {left = new Node();left.value = value;} else {left.store(value);}} else {if(right == null) {right = new Node();right.value = value;} else {right.store(value);}}}public boolean find(int value) {System.out.println("find : " + this.value);if(value == this.value) {return true;} else if(value < this.value) {if(left == null) {return false;} else {return left.find(value);} } else {if(right == null) {return false;} else {return right.find(value);}}}public void preSearch() {System.out.print(value + " ");if(left != null) {left.preSearch();}if(right != null) {right.preSearch();}}public void midSearch() {if(left != null) {left.midSearch();}System.out.print(value + " ");if(right != null) {right.midSearch();}}public void afterSearch() {if(left != null) {left.afterSearch();}if(right != null) {right.afterSearch();}System.out.print(value + " ");}}
0 0
- 二叉排序树,二叉树的中序,先序,后序遍历
- //二叉树的(二叉排序树)建立和先序遍历
- 二叉树的遍历(先序、中序、后序)
- 二叉树的先序、中序、后序遍历
- 二叉树的遍历:先序、中序、后序
- 二叉树的先序、中序、后序遍历
- 二叉树的先序、中序、后序遍历
- 二叉树的先序,中序,后序遍历
- 二叉树的先序、中序、后序遍历
- 二叉树的先序,中序,后序遍历
- 二叉树的先序、中序、后序遍历
- 二叉树的先序、中序、后序遍历
- 二叉树的先、中、后序遍历
- 二叉树的先,中,后序遍历
- 二叉树的先序遍历,后序遍历,中序遍历,层次遍历
- 二叉树的遍历(1)--先序遍历,中序遍历,后序遍历
- 二叉树的遍历代码(先序遍历,中序遍历,后序遍历)
- 二叉树树的先序遍历,中序遍历和后序遍历
- [Splay的应用]
- string类详解
- Java系列笔记(4) - JVM监控与调优
- Android之Style
- Oracle to_date()函数的用法
- 二叉排序树,二叉树的中序,先序,后序遍历
- [LeetCode]Find Minimum in Rotated Sorted Array I&II
- 树莓派连接天然气模块
- C++异常以及错误处理
- Groovy在ADF BC中的常见用法之一
- SWT中的进度条
- 通过make编译多文件的内核模块
- Mybatis Mapper动态代理方法 即 只写Dao接口 不谢Dao的实现类
- iOS 8 Xcode6 设置Launch Image 启动图片<转>