树的创建
这个树的创建游什么问题#include<stdio.h>
#include<ctype.h>
#define M 3
#define N 100
struct node {char data;
struct node *child[M];
}
typedef struct node NODE;
char[N];
int m;
NODE *creat_tree(s,m)
char s[];
int m;
{NODE *stack[N],*p=NULL,*q;
char ch;
int i,k=0,top=0;
ch=s[0];
while (ch!='\0')
{if(isalpha(ch))
{p=(NODE*)malloc(sizeof(NODE));
p->data=ch;
for(i=0;i<m;i++)
p->child[i]=Null;
}
else
switch(ch)
{case '(':stack[top++]=p;
break;
case ',':q=stack[top-1];
i=-1;
while(q->child[++i]!=NULL);
q->child[i]=p;
break;
case ')':q=stack[--top];
i=-1;
while(q->child[++i]!=NULL);
q->child=p;
q=p;
}
ch=s[++k];
}
return(p);
}