文章
19
粉丝
0
获赞
174
访问
6.6k
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include<map>
using namespace std;
typedef struct TNode
{
int data;
TNode *l,*r;
};
void creat(int x,TNode *&t)
{
if(t==nullptr)
{
t=new TNode;
t->data=x;
t->l = nullptr; //注意
t->r = nullptr;
}
else
{
if(x<t->data)
creat(x,t->l);
else
creat(x,t->r);
}
}
void pre(TNode *t){
if(t==nullptr) return;
cout<<t->data<<' ';
pre(t->l);
pre(t->r);
}
void in(TNode *t){
if(t==nullptr) return;
in(t->l);
cout<<t->data<<' ';
in(t->r);
}
void post(TNode *t){
if(t==nullptr) return;
post(t->l);
post(t->r);
cout<<t->data<<' ';
}
int main()
{
int n;
while(cin>>n)
{
map<int ,int> a;
TNode *t=nullptr;
for(int i=0;i<n;i++)
{
int x;
cin>>x;
if(a.count(x))
continue;
...
登录后发布评论
暂无评论,来抢沙发