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)); }
查看全文
相关阅读:
制作Elasticsearch的Parcel包和csd文件
zabbix监控安装1
linux官方源
Nginx优化详解
k8s-kubectl命令大全
详解keepalived配置和使用
keepalived工作原理和配置说明
linux 内核参数优化
批量更新软连接脚本
Java 常用知识点汇总(数据类型之间转换、字符串的相关操作-截取、转换大小写等)
原文地址:https://www.cnblogs.com/seebro/p/2476528.html
最新文章
Linux下安装Git
JetBrains WebStorm 如何从GitHub上克隆的代码
永久有效的 webstorm license server 20180808
最全PyCharm教程--for python
Centos7环境下FastRunner前端(FasterWeb)部署
浅谈软件项目开发过程中的主要项目风险及对策
synchronized (string.intern())
重新生成ssh
将本地的项目上传到码云
doc 常用命令
热门文章
EnableAutoConfiguration注解的工作原理(org.springframework.boot.autoconfigure.EnableAutoConfiguration=core.bean.MyConfig)
SpringBoot启动流程解析
使用fastjson解析数据后导致顺序改变问题
redis 部署相关
nodeJs项目 相关命令
https://blog.csdn.net/qq_35447305/article/details/78587691
使用sed -i对文本字符串进行增删改查
如何在CDH中配置YARN动态资源池的计划规则
Mmap强制缓存机制(转)
SparkStreaming概要
Copyright © 2011-2022 走看看