//树
#include<iostream>
#include<malloc.h>
using namespace std;
#define MAX 100
typedef struct bnode
{
char data;
struct bnode *left,*right;
}btree;
void createTree(btree *&b,string s)
{
int j=0;
char str;
str=s[j];
int k;
btree *p;
b=NULL;
int top=-1;
btree *stack[MAX];
while(str!='/0')
{
switch(str)
{
case '(':
top++;
stack[top]=p;
k=1;
break;
case ',':k=2;break;
case')':top--;break;
default:
p=( btree *)malloc(sizeof( btree));
p->data=str;
p->left=p->right=NULL;
// cout<<k<<endl;
if(b==NULL)
{
b=p;
}
else
{
switch(k)
{
case 1:stack[top]->left=p;break;
case 2:stack[top]->right=p;break;
}
}
}
j++;
str=s[j];
}
}
void inorder(btree *b)
{
if(b!=NULL)
{
inorder(b->left);
cout<<b->data<<" ";
inorder(b->right);
}
}
int main()
{
btree *b;
createTree(b,"(a(b(c),d(e(,f),g)))");
inorder(b);
return 0;
}