java实现二叉搜索树功能-创新互联

一、概念

邹城网站建设公司成都创新互联,邹城网站设计制作,有大型网站制作公司丰富经验。已为邹城1000+提供企业网站建设服务。企业网站搭建\外贸网站建设要多少钱,请找那个售后服务好的邹城做网站的公司定做!

  二叉搜索树也成二叉排序树,它有这么一个特点,某个节点,若其有两个子节点,则一定满足,左子节点值一定小于该节点值,右子节点值一定大于该节点值,对于非基本类型的比较,可以实现Comparator接口,在本文中为了方便,采用了int类型数据进行操作。

  要想实现一颗二叉树,肯定得从它的增加说起,只有把树构建出来了,才能使用其他操作。

二、二叉搜索树构建

   谈起二叉树的增加,肯定先得构建一个表示节点的类,该节点的类,有这么几个属性,节点的值,节点的父节点、左节点、右节点这四个属性,代码如下

static class Node{
    Node parent;
    Node leftChild;
    Node rightChild;
    int val;
    public Node(Node parent, Node leftChild, Node rightChild,int val) {
      super();
      this.parent = parent;
      this.leftChild = leftChild;
      this.rightChild = rightChild;
      this.val = val;
    }
    public Node(int val){
      this(null,null,null,val);
    }
    public Node(Node node,int val){
      this(node,null,null,val);
    }
  }

网站题目:java实现二叉搜索树功能-创新互联
路径分享:http://pwwzsj.com/article/dsesjd.html