本文共 751 字,大约阅读时间需要 2 分钟。
Java实现二叉查找树的前中后序遍历
二叉查找树 又名二叉搜索树,是二叉树结构中的一种,他的特点是每一个 节点最多有小于等于2的子节点 ,子节点可以为0,1,2个,二叉查找树 节点的左节点的数的值是小于他当前 节点的值,同时也小于右节点的值(左节点值<当期前节点值<右节点值)。他支持前中后序遍历,其中中序遍历得到的结果是有序的。
package tree;/** * @author ganxiang * IDE IntelliJ IDEA * @project_name and filename JavaDemo BinarySearchTree * @date 2020/06/10 0010 15:30 */public class BinarySearchTree { //定义二叉树结构 int data; BinarySearchTree left; BinarySearchTree right; public BinarySearchTree(){ this.left=null; this.right=null; } public BinarySearchTree(int data){ this.data=data; this.left=null; this.right=null; } public void insert(BinarySearchTree root,int data){ if (root.data
转载地址:http://heqzi.baihongyu.com/