/*
聽聽聽聽聽聽二叉树聽聽聽聽聽聽2014年5月15日
测试数据:abc聽聽de聽g聽聽f聽聽聽#
先序遍历顺序:abcdegf
中序遍历顺序:cbegdfa
后续遍历顺序:cgefdba
叶子结点是:cgf
*/
#include聽
#include聽
#include聽
#include聽
#include聽
#include聽
using聽namespace聽std;
typedef聽struct聽BINTREE
{
char聽data;
struct聽BINTREE聽*leftchild;
struct聽BINTREE聽*rightchild;
}*ptree,tree;
void聽creat_tree(ptree聽&t,string聽str)//创建二叉树
{
static聽int聽i聽=聽0;
if聽('聽'聽==聽str)
{
i++;
t聽=聽NULL;
}
else
{
t聽=聽new聽tree;
if聽(NULL聽==聽t)
{
coutleftchild,str);
聽聽聽聽聽聽聽聽聽聽聽聽creat_tree(t->rightchild,str);
}
}
return;
}
void聽first_visit(ptree聽t)//先序遍历
{
if聽(NULL聽!=聽t)
{
coutleftchild);
聽聽聽聽first_visit(t->rightchild);
}
}
void聽middle_visit(ptree聽t)//中序遍历
{
if聽(NULL聽!=聽t)
{
middle_visit(t->leftchild);
coutrightchild);
}
}
void聽last_visit(ptree聽t)//后序遍历
{
if聽(NULL聽!=聽t)
{
last_visit(t->leftchild);
last_visit(t->rightchild);
coutleftchild聽&&聽NULL聽==聽t->rightchild)
{
coutleftchild)
{
聽聽聽聽聽聽聽聽聽聽聽聽print_leaf(t->leftchild);
}
if聽(NULL聽!=聽t->rightchild)
{
print_leaf(t->rightchild);
}
}
}
void聽destroy_tree(ptree聽t)
{
if聽(NULL聽==聽t)
{
destroy_tree(t->leftchild);
destroy_tree(t->rightchild);
free(t);
}
}
bool聽is_creattree聽=聽false;
int聽main()
{
聽聽聽聽ptree聽t聽=聽NULL;
聽聽聽聽string聽str;
char聽ch聽=聽0;
cout |