[c++]代码库
//二叉树的建立、存储与遍历
#include <iostream.h>
struct BintrNode
{
char value;
BintrNode* lf;
BintrNode* rt;
};
void init ( BintrNode* &p )
{
char ch;
cin>>ch;
if ( ch!='!' )
{
p=new BintrNode;
p->value=ch;
init ( p->lf );
init ( p->rt );
}
else
{
p=NULL;
}
}
void pre ( BintrNode* p )
{
if ( p )
{
cout<<p->value;
pre ( p->lf );
pre ( p->rt );
}
}
void ino ( BintrNode* p )
{
if ( p )
{
ino ( p->lf );
cout<<p->value;
ino ( p->rt );
}
}
void pro ( BintrNode* p )
{
if ( p )
{
pro ( p->lf );
pro ( p->rt );
cout<<p->value;
}
}
void main()
{
BintrNode* bt;
init ( bt );
pre ( bt );
cout<<endl;
ino ( bt );
cout<<endl;
pro ( bt );
cout<<endl;
}
初级程序员
by: 是一只小龙呀 发表于:2021-11-11 19:42:27 顶(0) | 踩(0) 回复
1
回复评论