求助,哪位大虾看看这个括号匹配的程序里那里出错了啊?
#include <stdio.h>#include <malloc.h>
typedef struct node{
struct node *next;
char data;
}JD;
match(char E[])
{
JD *top,*s,*h;
int i;
h=(JD*)malloc(sizeof(JD*));
h->data='0';
h->next=NULL;
top=h;
while(E[i]!='\0')
{
char item;
if(E[i]=='(' || E[i]=='[' || E[i]=='{')
{
s=(JD*)malloc(sizeof(JD*));
s->data=E[i];
s->next=top;
top=s;
}
if(E[i]==')')
{
if(top==h){
printf("mismatch");
return 0;
}
item=top->data;
s=top;
top=s->next;
free(s);
if(item!=E[i]-1){
printf("mismatching!");
return 0;
}
}
else if(E[i]==']' || E[i]=='}'){
if(top==h){ /*测试堆栈是否为空*/
printf("mismatching!");
return 0;
}
item=top->data; /*退栈*/
s=top;
top=s->next;
free(s);
if(item!=E[i]-2){
printf("mismatching!");
return 0;
}
}
i++;
}
if(top==h)
printf("matching!\n");
else
printf("mismatching!\n");
return 1;
}
void main()
{
char s[100]={0};
printf("Please enter the parentheses arithmetic expression:\n");
scanf("%s",s);
match(s);
}