//TreeNode.h头文件
#include
using namespace std;
class BtreeNode
{
public:
char data;
BtreeNode *left,*right;
BtreeNode(char da);
~BtreeNode();
void XianxuChild(BtreeNode *bn);
void ZhongxuChild(BtreeNode *bn);
void HouxuChild(BtreeNode *bn);
};
BtreeNode::BtreeNode(char da)
{
data=da;
left=NULL;
right=NULL;
}
BtreeNode::~BtreeNode()
{
}
void BtreeNode::XianxuChild(BtreeNode *bn)
{
if(bn!=NULL)
{
cout<
XianxuChild(bn->left);
XianxuChild(bn->right);
}
}
void BtreeNode::ZhongxuChild(BtreeNode *bn)
{
if(bn!=NULL)
{
ZhongxuChild(bn->left);
cout<
ZhongxuChild(bn->right);
}
}
void BtreeNode::HouxuChild(BtreeNode *bn)
{
if(bn!=NULL)
{
HouxuChild(bn->left);
HouxuChild(bn->right);
cout<
}
}
//BinaryTree.h头文件
#include
#include"TreeNode.h"
using namespace std;
class Tree
{
public:
BtreeNode *root;
Tree(char *ch);
~Tree();
BtreeNode *createtree(char *ch);
void XianxuBianli();
void ZhongxuBianli();
void HouxuBianli();
};
Tree::Tree(char *ch)
{
root=NULL;
if(ch!=" ")
{
cout<<"建立一棵二叉树:"<
cout<
else
{
cout<<"树已建立!"<
}
Tree::~Tree()
{
}
BtreeNode* Tree::createtree(char *ch)
{
BtreeNode *bn=NULL;
int i=0;
//while(i<100)
//{
if(ch[i]!='.')
{
bn=new BtreeNode(ch[i]);
i++;
bn->left=createtree(ch);
bn->right=createtree(ch);
}
else
{
i++;
}
//}
return bn;
}
void Tree::XianxuBianli()
{
cout<<"先序遍历二叉树:";
root->XianxuChild(root);
cout<
void Tree::ZhongxuBianli()
{
cout<<"中序遍历二叉树:";
root->ZhongxuChild(root);
cout<
void Tree::HouxuBianli()
{
cout<<"后序遍历二叉树:";
root->HouxuChild(root);
cout<
#include
#include"BinaryTree.h"
using namespace std;
//主程序
void main()
{
char *ch="123.4..56..78..";
Tree Tree1(ch);
Tree1.XianxuBianli();
Tree1.ZhongxuBianli();
Tree1.HouxuBianli();
}
编译出现错误,说“unhandled exception in xx.exe(NTDLL.DLL):0xC00000FD :stack overflow”.我不知道怎么改,希望高手能帮帮我,十分感谢!!!