文章

75

粉丝

0

获赞

147

访问

8.7k

头像
二叉排序树2 题解:c++
P1411 华中科技大学机试题
发布于2026年2月27日 14:28
阅读数 17

#include <bits/stdc++.h>
using namespace std;

typedef struct node{
    int data;
    node *left,*right;
}*Tree;
void Insert(node* &t,int val){
    if(t == nullptr){
        t = new node();
        t->data = val;
        t->left = nullptr;
        t->right = nullptr;
    }else{
        if(t->data > val) Insert(t->left,val);
        else if(t->data < val) Insert(t->right,val);
    }
}
void Pre(Tree t){
    if(t != nullptr){
        cout << t->data << " ";
        Pre(t->left);
        Pre(t->right);
    }
}
void In(Tree t){
    if(t != nullptr){
        In(t->left);
        cout << t-&g...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发