c语言判断一字符串左右括号是否匹配的问题!求助

如题所述

由于没有分配空间,,,修改如下
#include
#include
#include
//
!!!分配内存头文件
#define
m
20
typedef
char
ElemType;
typedef
struct
{
ElemType
stack[m];
int
top;
}stacknode;
stacknode
*sp;
Init(stacknode
*st)
{
st->top=0;
return
0;
}
void
Push(stacknode
*st,ElemType
x)
{
if(st->top==m)
printf("The
stack
is
overflow!\n");
else
{
st->top=st->top+1;
st->stack[st->top]=x;
}
}
void
Pop(stacknode
*st)
{
st->top=st->top-1;
}
main()
{
char
s[m];
int
i;
printf("Creat
a
stack!\n");
sp
=
(stacknode
*)malloc(sizeof(stacknode));
//
!!!添加的语句
Init(sp);
printf("Input
a
expression:\n");
gets(s);
for(i=0;i
top==0)
printf("左右括号是匹配的!\n");
else
printf("左右括号是不匹配的!\n");
}
温馨提示:答案为网友推荐,仅供参考