#include<stack>
using namespace std;
typedef struct node
{
char num;
struct node *rchild;
struct node *lchild;
}Node;
void display(Node *p)
{
if(p!=NULL)
{
display(p->lchild);
display(p->rchild);
printf(“%c “,p->num);
}
}
int main()
{
int k=0,i,j;
Node *T,*p;
char exp[100],ch;
int lens=0,flag=1;
stack<Node *> s;
gets(exp);
lens=strlen(exp);
for(i=0;i<lens&&flag;i++)
{
ch=exp[i];
switch(ch)
{
case ‘(‘:
{ s.push(p);k=0;break;}
case ‘)’:
{ if(!s.empty()) {s.pop();}else flag=0;break;}
case ‘,’:
{
k=1;
break;
}
default:
{
p=(Node *)malloc(sizeof(Node));
p->lchild=p->rchild=NULL;
p->num=ch;
if(s.empty())
{
T=p;
}else
{
if(k==0)
{
s.top()->lchild=p;
}else
{
s.top()->rchild=p;
}
}
}
}
}if(flag==0) printf(“出错!”);
display(T);
return 0;
}