对指针的理解运用还欠加强
#include<stdio.h>
#include<iostream>
#include<string>
#include<string.h>
#include<math.h>
#include<functional>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
const int maxn =100005;
const int inf = 1<<30;//0x7f;
typedef __int64 LL;
int n;
struct node
{
int w;
node *lch,*rch;
};
node *updata( int u,node *root )
{
if( root == NULL ){
root = new node;
root->w = u; root->lch = root->rch = NULL;
return root;
}
else if( root->w > u )
root->lch = updata( u,root->lch );
else if( root->w < u )
root->rch = updata( u,root->rch );
return root;
}
void fun( node *root,int flag )
{
if( flag )
printf("%d",root->w);
else
printf(" %d",root->w);
if( root->lch != NULL )
fun( root->lch,0 );
if( root->rch != NULL )
fun( root->rch,0 );
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("data.txt","r",stdin);
#endif
int u;
while( scanf("%d",&n) != EOF )
{
node *root = NULL;
for( int i = 1; i <= n; i ++ ){
scanf("%d",&u);
root = updata(u,root);
}
fun( root,1 );
puts("");
}
return 0;
}