c语言括号匹配应用程序堆栈

算法提示:

1)左括号出现的地方,放入栈中;

2)每当右括号出现时,首先检查堆栈是否为空。

如果堆栈为空,则意味着“右括号”是多余的。

否则,与栈顶元素相比,

如果它们匹配,则弹出左括号。

,

否则,它表示不匹配。

3)在表达式检查结束时,

如果堆栈为空,则意味着表达式中的匹配是正确的。

否则,不止是“左括号”。

c语言括号匹配问题(stack)我写的程序感觉有点不对,找不到原因。 大概有三个问题:

资源未被清理。

部分逻辑错误

堆栈操作错误

用以下注释进行修订:

# includestdio.h

#includestdlib.h

#includestring.h

结构节点

{

夏尔·付豪;

结构节点* next

};

结构S

{

结构节点* top

结构节点*底部;

};

void start(struct S * S);

void clean(struct S * S);

void end(struct S * * S);

char yulan(struct S * S);

void ruzhan(struct S *s,char a);

char Chu Zhan(struct S * S);

int pan Duan(struct S * S);

int match(char a,char b);

int main()

{

int n,a,I;

字符排列

相关文章

发表新评论