void Deltree(BTNode *b)
{
if(b!=NULL)
{
Deltree(b->lchild);
Deltree(b->rchild);
free(b);
}
}//Recreate函数调用,用于删除原来的树
void Recreate(BTNode *&b)
{
char judge;
std::cout<<"将会删除原先二叉树,删除吗?(y/n)"<<endl;
std::cin>>judge;
if('Y'==toupper(judge))
{
Deltree(b);
std::cout<<"删除完毕"<<endl;
}
else
{
std::cout<<"错误,退出"<<endl;
return;
}
std::cout<<"请输入二叉树用括号表示法,以@结束。例:\"A(B(D,E(H(J,K(L,M(,N))))),C(F,G(,I)))@\"";
std::cout<<endl;
std::cout<<"请输入:";
int top=-1;
BTNode *e;
e=NULL;
BTNode *s[30];
int k;
BTNode *p;
string chs;
std::cin>>chs;
string::iterator iter;
iter=chs.begin();
char ch;
ch=*iter;
while(ch!='@') //就是从这里开始起有错误的
{
switch(ch)
{
case '(':
top++;s[top]=p;k=1;break;
case ')':
top--;break;
case ',':
k=2;break;
default:
p=new BTNode;
p->data=ch;p->lchild=p->rchild=NULL;
if(e==NULL) e=p;
else
{
if(k==1) s[top]->lchild=p;
else s[top]->rchild=p;
}
}
iter++;
ch=*iter;
}
b=e;
}
[此贴子已经被作者于2006-6-7 14:48:09编辑过]