把括号形式的二叉树转换成链表形式输出
#include<stdio.h>#include<malloc.h>
#include<string.h>
#define n 10
#define null 0
typedef struct
{
char data[n];
int top;
}seqstack;
typedef struct node2
{
char data;
struct node2 *lchild;
struct node2 *rchild;
}btnode;
void main()
{
btnode *s[n],*b,*p=null;
int top=-1,tag,j;
char ch,str[n];
printf("输入:\n");
for(j=0;j<n;j++)
str[j]=getchar();
ch=str[0];
while(ch!='\n')
{
switch(ch)
{
case'(':top++;s[top]=p;tag=1;break;
case')':top--;break;
case',':tag=2;break;
default:p=(btnode *)malloc(sizeof(btnode));
p->data=ch;
p->lchild=p->rchild=null;
if(b==null) b=p;
else
{
switch(tag)
{
case 1:s[top]->lchild=p;break;
case 2:s[top]->rchild=p;break;
}
}
}
j++;ch=str[j];
}
if(b!=null)
printf("%c",b->data);
else if(b->lchild!=null)
{printf("%c",p->lchild->data);p=p->lchild;}
else{printf("%c",p->rchild->data);p=p->rchild;}
}大侠帮忙看看那错了?