广义表建立二叉树不知道哪里错了
#include "stdio.h"#include<stdlib.h>
#define N 10
struct btree{
char data;
struct btree*left;
struct btree*right;
};
void print(struct btree*head)
{
if(head){
printf("%c",head->data);
print(head->left);
print(head->right);
}
}
main()
{
char *a,b[N];
int top=-1,flag,i=0;
struct btree*stack[N],*p,*head;
head=NULL;
a=b;
gets(a);/*输入广义表*/
while(a[i]) /*扫描广义表字符*/
{
switch(a[i]){
case' ':
break;
case'(':
top++;
stack[top]=p;
flag=1;
break;
case')':
top--;
break;
case',':
flag=0;
break;
defalut:
p=malloc(sizeof(struct btree));
p->data=a[i];
p->left=p->right=NULL;
if(head==NULL)
head=p;
else{
if(flag==1)
stack[top]->left=p;
else
stack[top]->right=p;
}
}
i++;
}
print(head);
}
不知道哪里错了,请帮我看看,输入了没有输出结果