C++中生成一个二叉树

来源:百度知道 编辑:UC知道 时间:2024/06/30 13:51:09
我要一个C++的程序,C的不要,生成一个二叉树,三种都遍历都要,二叉树的数据中含有一个data[3]是个数组,visite实现对data的访问,带程序注释的,要能看懂的,能运行的。可以再有50~100分的追加奖励
要win32平台下的,用Visual studio2005 能运行的

我的VC6的WIN32的,不能用拉倒。
#include<iostream>
using namespace std;
struct tree
{
int data;
struct tree *l,*r;
};
void insert(tree *&proot,tree *pnode)
{
if(proot==NULL)
{
proot=pnode;
return;
}
else
{
if(proot->data<=pnode->data)
{
insert(proot->l,pnode);
}
else
insert(proot->r,pnode);
}
}
void mid_print(tree *proot)//中序遍历
{
if(proot==NULL)
return;
mid_print(proot->l);
cout<<proot->data<<" ";
mid_print(proot->r);
}
void front_print(tree *proot)//前序遍历
{
if(proot==NULL)
return;
cout<<proot->data<<" ";
front_print(proot->l);
front_print(proot->r);
}
void behind_print(tree *proot)//后序遍历
{
if(proot==NULL)
return;
behind_print(proot->l);
beh