栈的应用:中缀表达式转化为后缀表达式(逆波兰表达式)
2016-02-04 20:06
387 查看
#include <iostream> #include <cstdlib> #include <cstdio> #include "MyownStack.h" using namespace std; const int Max = 1000; int main() { MyOwnStack <char> s; char c,e; cout<<"请输入中缀表达式,以#作为结束标志:\n"; while(1){ scanf("%c",&c); while(c >= '0'&&c <= '9'){ cout<<c; scanf("%c",&c); if(c<'0'||c>'9') cout<<" "; } if('#' == c) break; if(')' == c) while(1){ e=s.Pop(); if('(' == e) break; cout<<e<<" "; } if('+' == c || '-' == c){ while(1){ if(!s.stackLen()){ s.Push(c); break; } e=s.Pop(); if('(' == e){ s.Push(e); s.Push(c); break; } cout<<e<<" "; } } if( '*' == c|| '/' == c|| '(' == c) s.Push(c); } while(s.stackLen()){ e=s.Pop(); cout<<e<<" "; } return 0; }
相关文章推荐
- nyoj835 吉他练习 (水题)
- 命令行之2048
- MongoDB基本命令
- 【51单片机】(手把手教你)1602液晶屏-基础篇
- poj3614 二分图最大匹配 or 贪心
- Java NIO4:Socket通道
- 修改hosts文件
- 栈的应用:逆波兰表达式
- [悬线法] BZOJ 3039 玉蟾宫
- 使用批处理运行jar控制台程序
- Dapper 条件语句(Where) 中参数使用
- Android总结——开始一个Activity
- seoreZxirtaMteS.73
- MongoDB在linux下的启动
- MFC杂项01 重写键盘相应事件 +创建和装载常规dll文件 +GetVolumeInformation获取本地硬盘序列号
- Greenplum同步到Oracle
- openjpeg:jpeg2000(j2k)图像内存解压缩(解码)
- Android性能优化之图片的本地和网络缓存
- 【slighttpd】基于lighttpd架构的Server项目实战(3)—Master&Worker模式
- Hadoop分布式文件系统——HDFS