首页 > 其他 > 详细

[模板]二叉搜索树

时间:2018-11-28 14:53:11      阅读:202      评论:0      收藏:0      [点我收藏+]

tips:模板是写给自己的,所以大家可能有些看不懂,请移步参观其他dalao的模板。

一、结点构造

struct Node
{
    int data,lson,rson;
}A[N];

二、插入insert

void insert(int w_pos,int pos)
{
    if(A[w_pos].data<A[pos].data){
        if(!A[pos].lson)A[pos].lson=w_pos;
        else insert(w_pos,A[pos].lson);
    }
    else{
        if(!A[pos].rson)A[pos].rson=w_pos;
        else insert(w_pos,A[pos].rson);
    }
    return;
}

三、查找find

查找最小数

int find(int pos)
{
    if(!A[pos].lson)return pos;
    find(A[pos].lson);
}

查找最大数

int find(int pos)
{
    if(!A[pos].rson)return pos;
    return find(A[pos].rson);
}

四、删除clear

我不会呀啊啊啊啊啊,所以还没写耶,以后有时间会补的。——2018.11.28

 

[模板]二叉搜索树

原文:https://www.cnblogs.com/lihepei/p/10031715.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!