[模板]二叉搜索树

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