C++辅导:二叉树
/*2Tree的基本操作*/
# include
struct tree
{
int data;
结构树* left
结构树*右;
};
typedef结构树treenode
typedef treenode * b _ tree;
b _ tree creat()
{
char ch;
b _ tree new node;
ch = getchar();
if (ch== ' ')返回(NULL);
else
{ newnode =(b _ tree)malloc(sizeof(treenode));
new node-> data = ch;
new node-> left = creat(new node);
new node-> right = creat(new node);
}
return new node;
}
void front _ print(b _ tree root)
{
if(root!= NULL)
{
printf("[% c]",root-> data);
front _ print(root-> left);
front _ print(root-> right);
}
}
void middle _ print(b _ tree root)
{
if(root!= NULL)
{
middle _ print(root-> left);
printf("[%c]",root-> data);
middle _ print(root-> right);
}
}
0条评论