+ -
当前位置:首页 → 问答吧 → 帮我看看我的广义表建立,输出出了什么问题,代码很短

帮我看看我的广义表建立,输出出了什么问题,代码很短

时间:2011-11-07

来源:互联网

根据字符串建立广义表并输出 在运行过程中出问题,
void InitLists(GList &p,char*s)
{
if(*s=='\0') return;
if(*s=='(')
{
p=new GLNode;
p->tag=LIST;
InitLists(p->ptr.hp,++s);
}
else if((*s>='a'&&*s<='z')||(*s>='A'&&*s<='Z'))
{
p=new GLNode;
p->tag=ATOM;
p->atom=*s;
}
else if(*s==',')
{
p->tag=LIST;
InitLists(p->ptr.tp,++s);
}
else if(*s==')')
{
p=NULL;
return;
}
else return;

}
void PrintLists(GList p)
{
if(p==NULL)return;
else if(p->tag==ATOM)cout<<p->atom;
else{
cout<<"(";
PrintLists(p->ptr.hp);
p=p->ptr.tp;
while(p){
PrintLists(p->ptr.hp);
p=p->ptr.tp;
}
}

}

作者: shimachao   发布时间: 2011-11-07

求高手啊!帮帮忙啦

作者: shimachao   发布时间: 2011-11-07

热门下载

更多