/* DATE: 2006-12-02 BY:snowhill */
#include "iostream.h"
/* definition */
struct bitree
{
int data;
bitree *lchild,*rchild;
};
//插入
void Insert(bitree *&BST,int x)
{
if(BST==NULL)
{
bitree *p=new bitree;
p->data=x;
p->lchild=p->rchild=NULL;
BST=p;
}
else if(BST->data>=x)
Insert(BST->lchild,x);
else
Insert(BST->rchild,x);
}
//create a binary Tree with n nodes
bitree *create(bitree *BST,int n)
{
int x;
BST=NULL;
for(int i=1;i<=n;i++)
{
cin>>x;
Insert(BST,x);
}
if(BST==NULL)
cout<<"It must be fun!"<<endl;
return BST;
}
//先序遍历
void preorder(bitree *BST)
{
bitree *p;
p=BST;
if(p!=NULL)
{
cout<<p->data<<"->";
preorder(p->lchild);
preorder(p->rchild);
}
}
/* 主函数 */
void main()
{
bitree *BST;
BST=NULL;
BST=create(BST,4);
preorder(BST);
}