文章

16

粉丝

134

获赞

0

访问

3.5k

头像
二叉搜索树 题解:AC,建立二叉搜索树以及比较两个二叉树是否相同
P1317 浙江大学机试题
发布于2024年4月3日 09:46
阅读数 136

//判断不同的输入序列是否能组成相同的二叉搜索树
#include<bits/stdc++.h>
using namespace std;
struct Tree {
    int data;
    struct Tree* lchild;
    struct Tree* rchild;
};
void _insert(struct Tree* &root, int t) {
    if(root == NULL) {
        root = new Tree;
        root->data = t;
        root->lchild = NULL;
        root->rchild = NULL;
        return;
    } else if(t < root->data) {
        _insert(root->lchild, t);
    } else if(t > root->data) {
        _insert(root->rchild, t);
    } else if(t == root->data)
        return;
}
bool cmp(struct Tree* r1, struct Tree* r2) {
    if(r1 == NULL && r2 == NULL)
        return true;
    if(r1 == NULL || r2 == NULL)
&...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发