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)); }
查看全文
相关阅读:
C#对List排序的三种方式的比较
unity跨平台及热更新学习笔记-C#中通过程序域实现DLL的动态加载与卸载
总结下C#中有关结构体的几个问题
C#中通过逻辑^(异或)运算交换两个值隐藏的巨坑!!!
unity实现批量删除Prefab上Miss的脚本组件
Oracle构造列思想,decode,case,sgin,pivot四大金刚
Oracle-计算岁数
Oracle 集合
Oracle 综合例子应用01
Oracle 事实表,维表,多对多
原文地址:https://www.cnblogs.com/seebro/p/2476528.html
最新文章
LoadRunner之IP欺骗
LoadRunner服务水平协议SLA
liunx命令简介
字符编码的前世今生
性能测试简介
Appium学习2-Appium-desktop的使用
Appium学习1-安装
Python的字典、列表合并
python创建字典的三种方式
Pytest学习10-pytest与unittest的区别
热门文章
Pytest学习9-常用插件
pytest学习8-运行上次执行失败的用例
Pytest学习7-参数化
Pytest学习6-跳过或xfail失败的用例
pytest学习5-mark用例分类
C#在类外部实现对私有字段/私有属性的修改及调用
项目中的单例如何管理
直线型地图点连线模拟
Excel数据变动比较工具-SpreadsheetCompare
unity跨平台及热更新学习笔记-Unity中通过程序域实现DLL的动态加载
Copyright © 2011-2022 走看看