第五周项目三 括号的匹配(栈的应用)
来源:互联网 发布:java特种兵入门java 编辑:程序博客网 时间:2024/06/01 16:46
问题及代码
/**Copyright(c)2017,烟台大学计算机学院*All right reserved.*文件名:main.cpp sqstack.h sqstack.cpp*作者:王万兴*完成日期:2017年9月28日*版本号:v1.0**问题描述:括号匹配*输入描述:表达式*程序输出:见运行结果*/#include <stdio.h>#include "sqstack.h"int main(){ char c; char st[50]; int d=1, i; SqStack *s; InitStack(s); printf("请输入表达式:"); scanf("%s", st); for(i=0; st[i]!='\0'&&d; i++) { switch(st[i]) { case'(': case'[': case'{': Push(s, st[i]); break; case')': Pop(s, c); if(c!='(') d=0; break; case']': Pop(s, c); if(c!='[') d=0; break; case'}': Pop(s,c); if(c!='{') d=0; break; } } if(StackEmpty(s)&&d==1) printf("配对正确!!\n"); else printf("配对错误!!\n"); return 0;}算法库:点击打开链接
运行结果
正确
错误
知识点总结
先进后出,最后的括号,最先结束,pop,如果正确,栈为空,如果不匹配,则结束循环,配对错误。
阅读全文
0 0
- 第五周项目三-括号的匹配(栈)
- 第五周项目三 括号的匹配(栈的应用)
- 第五周项目三 括号的匹配
- 第五周【项目三-括号的匹配】
- 第五周- 项目三 括号的匹配
- 第五周--项目三--括号的匹配
- 第五周项目三-括号的匹配
- 第五周 项目三 括号的匹配
- 第五周 项目三----括号的匹配
- 第五周项目三 括号的匹配
- 第五周项目三 括号的匹配
- 第五周项目三 括号的匹配
- 第五周项目三(括号的匹配)
- 第五周线性表 项目(三)括号的匹配
- 第五周——项目三—括号的匹配
- 第五周项目三—括号的匹配
- 第五周项目三——括号的匹配
- 第五周项目三—括号的匹配
- rs232 ,rs485和TTL电平的总结
- 新版sublime text3破解码
- 第四周 项目3
- 我的python学习笔记.创建和使用类
- 使用EventBus出现java.lang.NoClassDefFoundError: android/os/PersistableBundle错误
- 第五周项目三 括号的匹配(栈的应用)
- 磁盘备份工具dcfldd
- javaweb接口安全设计预备知识--java自定义注解
- spring batch与spring cloud pdf文档和框架分享
- 机器人学杂记
- hash table
- 设计模式:单例模式
- 顺序线性表的基本操作(C语言实现)
- response.setContentType()的作用及参数