博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java实现二叉查找树的前中后序遍历
阅读量:3960 次
发布时间:2019-05-24

本文共 751 字,大约阅读时间需要 2 分钟。

Java实现二叉查找树的前中后序遍历

文章目录

1,认识二叉查找树

二叉查找树 又名二叉搜索树,是二叉树结构中的一种,他的特点是每一个 节点最多有小于等于2的子节点 ,子节点可以为0,1,2个,二叉查找树 节点的左节点的数的值是小于他当前 节点的值,同时也小于右节点的值(左节点值<当期前节点值<右节点值)。他支持前中后序遍历,其中中序遍历得到的结果是有序的。

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

3,运行展示

在这里插入图片描述

4,画出二叉树的结构

在这里插入图片描述

转载地址:http://heqzi.baihongyu.com/

你可能感兴趣的文章