表达式的括号匹配,,在运行的时候出现Process returned -1073740940 (0xC0000374),哪里有问题,如何解决
#include <stdio.h>
#include <stdlib.h>
typedef struct Node
{
char data;
struct Node *next;
}Node;
typedef struct stack
{
Node *top;
Node *bottom;
}stack;
void InitStack (stack *s)
{
s->bottom=(Node*)malloc(sizeof(Node));
s->bottom=s->top;
s->bottom->next=NULL;
}
void Push (stack *s,char c)
{
Node *p;
p=(Node*)malloc(sizeof(Node));
p->data=c;
p->next=s->top->next;
s->top->next=p;
}
void Pop (stack *s)
{
Node *p;
p=s->top;
s->top=p->next;
free (p);
}
int Empty(stack *s)
{
return (s->top==NULL);
}
void BracketMatch (stack *s,char str[])
{
char ch;
for (int i=0;str[i]!='\0';i++)
{
switch (str[i])
{
case '(':
case '[':
case '{':
Push (s,str[i]);
break;
case ')':
case ']':
case '}':
if (Empty(s))
{
printf("no");
return ;
}
else
{
ch=s->top->data;
if (ch==str[i])
{
Pop(s);
}
else
{
printf("no");
return ;
}
}
}
}
}
int main()
{
stack *s;
s=(stack*)malloc(sizeof(stack));
char str[100];
gets(str);
InitStack(s);
BracketMatch(s,str);
if (Empty(s))
{
printf("yes");
}
else
{
printf("no");
}
return 0;
}