zoukankan
html css js c++ java
后缀运算器(已补全)
#include "mystack.h" #include <iostream> using namespace std; char get_command() { char command; bool waiting = true; cout << "Select command and press <ENTER> : "; while (waiting){ cin >> command; if (command == '?' || command == '=' || command == '+' || command == '-' || command == '*' || command == '/' || command == 'q') waiting = false; else{ cout << "Please enter a valid command:"<< endl << "[?]push to stack [=]print top" << endl << "[+][-][*][/]" << endl << "[q]exit." << endl; } } return command; } bool do_command(char command, Stack &numbers) { double p,q; switch (command){ case '?': cout << "Enter a real number." <<flush; cin >> p; if (numbers.push(p) == overflow) cout << "Waring :stack full,lost numbers" <<endl; break; case '=' : if(numbers.top(p) == underflow) cout << "Stack empty" <<endl; else cout << p <<endl; break; case '+': if (numbers.top(p) == underflow) cout << "stack empty" <<endl; else{ numbers.pop(); if (numbers.top(q) == underflow) cout << "stack has just one entry" <<endl; numbers.push(p); } else{ numbers.pop(); if (numbers.push(p+q) == overfloww) cout << "Warring : stack full,lost result" << endl; } } break; case '-': if (numbers.top(p) == underflow) cout << "stack empty" <<endl; else{ numbers.pop(); if (numbers.top(q) == underflow) cout << "stack has just one entry" <<endl; numbers.push(p); } else{ numbers.pop(); if (numbers.push(p-q) == overfloww) cout << "Warring : stack full,lost result" << endl; } } break; case '*': if (numbers.top(p) == underflow) cout << "stack empty" <<endl; else{ numbers.pop(); if (numbers.top(q) == underflow) cout << "stack has just one entry" <<endl; numbers.push(p); } else{ numbers.pop(); if (numbers.push(p*q) == overfloww) cout << "Warring : stack full,lost result" << endl; } } break; case '/': if (numbers.top(p) == underflow) cout << "stack empty" <<endl; else{ numbers.pop(); if (numbers.top(q) == underflow) cout << "stack has just one entry" <<endl; numbers.push(p); } else{ if (q == 0) cout << "againt / precept!" <<endl; else numbers.pop(); if (numbers.push(p/q) == overfloww) out << "Warring : stack full,lost result" << endl; } } case 'q'; cout << "calculation finished.\n"; return false; } return true; } void main() { Stack numbers; while (do_command(get_command(),stored_numbers)); }
查看全文
相关阅读:
01Tensorflow学习之Tensorflow基本介绍
C#四舍五入说明
3类与对象——重拾Java
1Java语言概述——重拾Java
Android 字体效果
Python相关资料收集
2013.11.23思科研发中心面试
【转】理解同步与异步
OpenCV中的SURF算法介绍
OpenCV中Kinect的使用(3)
原文地址:https://www.cnblogs.com/seebro/p/2476528.html
最新文章
【浮*光】#树形DP# 树形DP的习题集
【暖*墟】#数论# 莫比乌斯反演的学习与练习
【暖*墟】#图论计数# 矩阵树定理的学习与练习
【浮*光】#矩阵乘法# 矩阵优化的学习与练习
上百本电子书(Java/Hadoop/Spark/Linux/机器学习/)免费分享 百度云持续更新
500GJava/Hadoop/Spark/机器学习...视频教程免费分享 百度云持续更新
如何进BAT,有了这个篇面试秘籍,成功率高达80%!!(附资料)
教程+资源,python scrapy实战爬取知乎最性感妹子的爆照合集(12G)!
大话Spark(9)-源码之TaskScheduler
大话Spark(8)-源码之DAGScheduler
热门文章
大话Spark(7)-源码之Master主备切换
大话Spark(6)-源码之SparkContext原理剖析
大话Spark(5)-三图详述Spark Standalone/Client/Cluster运行模式
大话Spark(4)-一文理解MapReduce Shuffle和Spark Shuffle
大话Spark(3)-一图深入理解WordCount程序在Spark中的执行过程
调试IE11的方法
angular.copy的效率慢的替换方式
C#实现文件和目录的复制替换
Dotfuscator Professional Edition获取代码发布和混淆代码
02 Tensorflow的安装配置
Copyright © 2011-2022 走看看