#include<fstream>
using namespace std;
struct node
{
int data;
node *lch,*rch;
};
ifstream cin("btree.in");
ofstream cout("btree.out");
void ins(node *&root,int x)
{
if (root==NULL)
{
root=new(node);
root->data=x;
root->lch=root->rch=NULL;
return;
}
if (x<root->data) ins(root->lch,x);
else ins(root->rch,x);
}
void midord(node *root)
{
if (root)
{
midord(root->lch);
cout<<root->data<<" ";
midord(root->rch);
}
}
int main()
{
int n,x;
node *root;
root=NULL;
cin>>n;
for (int i=0;i<n;i++)
{
cin>>x;
ins(root,x);
}
midord(root);
system("pause");
return 0;
}
posted on 2013-01-18 16:37
龙在江湖 阅读(212)
评论(0) 编辑 收藏 引用 所属分类:
二叉树