要给这个水题ORZ。。。。。。。我真的是弱爆了,这个烂题耽误我快一下午。。。。
我他妈的弱爆了。。。各种跪烂。。。上午TC的一题各种跪。。。。下午又是各种ORZ。。就是给出二叉排序树的先序遍历,求后序,,,,,对先序排下序就有中序了,,,各种OTL,,,其实直接建树就行。。。然后直接后序。。。
#include<cstdio>
//#include<stdlib.h>
#include<algorithm>
#include<vector>
using namespace std;
struct node
{
int data;
node *lc,*rc;
node(int x)
{
data=x;lc=rc=NULL;
}
};
void build(node *t,int v)
{
if(t->data>v)
{
if(t->lc==NULL)
{
t->lc=new node(v);
}
else
build(t->lc,v);
}
else
{
if(t->rc==NULL)
{
t->rc=new node(v);
}
else
build(t->rc,v);
}
}
void post(node *t)
{
if(t!=NULL)
{
post(t->lc);
post(t->rc);
printf("%d\n",t->data);
}
}
int main()
{
/*freopen("1.txt","r",stdin);
freopen("2.txt","w",stdout); */
int x;
scanf("%d",&x);
node tm(x);
while(~scanf("%d",&x))
{ build(&tm,x);
}
post(&tm);
return 0;
}