stack和queue的初级应用
来源:互联网 发布:全面战争战锤优化 编辑:程序博客网 时间:2024/06/09 17:58
栈stack的初级应用:
stack:操作 比较和分配堆栈 empty() 堆栈为空则返回真 pop() 移除栈顶元素 push() 在栈顶增加元素 size() 返回栈中元素数目 top() 返回栈顶元素 //数值运算,十进制转八进制#include<cstdio>#include<iostream>#include<stack>#include<cstring>using namespace std;int main(){ int n; cin>>n; int m; stack<int>s; while(n/8) { m=n%8; n=n/8; s.push(m); } m=n%8; s.push(m); while(!s.empty()) { cout<<s.top(); s.pop(); } cout<<endl; return 0;}
sdut2133
利用二目运算符,每次遇到运算符,就从栈中取出两个数,进行运算后再将其写入栈中,千万不要忘了取出之后,将此值从栈中移除。
//后缀表达式的计算#include<iostream>#include<cstdio>#include<cstring>#include<stack>using namespace std;int main(){ char s[1002]={0}; stack<int>s1; while(~scanf("%s",s)) { int i,j; for(i=0;i<strlen(s);++i) { if(s[i]=='#') break; if(s[i]=='+'||s[i]=='-'||s[i]=='*'||s[i]=='/') { int n=s1.top(); s1.pop(); int m=s1.top(); s1.pop(); int k; switch(s[i]) { case '+':k=n+m;break; case '-':k=m-n;break; case '*':k=n*m;break; case '/':k=m/n;break; } s1.push(k); continue; } s1.push(s[i]-'0'); } cout<<s1.top()<<endl; } return 0;}
阅读全文
0 0
- stack和queue的初级应用
- Queue和Stack的应用
- STL中stack和queue的用法
- 【备忘】stack和queue的常用参数
- c++ 中 stack 和 queue 的用法
- Queue和Stack头文件的使用
- STL中stack和queue的用法
- STL----stack 和queue的使用
- 【数据结构】Stack和Queue的模拟实现
- c++ 中 stack和queue的使用方法
- stack和queue的错题
- STL的stack和queue读书笔记
- 适配器stack和queue的使用
- 浅谈 Stack 和 Queue 的比较学习
- C# Queue 和Stack的实现
- (队列的应用5.3.1)ZOJ 3210 A Stack or A Queue?根据进入结构的序列和离开结构的序列确定是stack还是queue)
- Queue和Stack
- stack和queue详解
- Android悬浮框
- 2017.7.5(转)python2.7,一个困扰了我一天的print问题
- MOOC清华《程序设计基础》第5章:求n的阶乘(用递推法做)
- Netty线程模型(中)
- springMVC-day02
- stack和queue的初级应用
- 机房重构总结--代码篇
- 使用ResourceBundle 读取资源配置信息
- linux内核数据结构之kfifo
- 线程的创建和退出
- Error:The number of method references in a .dex file cannot exceed 64K 问题解决
- memcache安装与使用教程(已经很详细了)
- http://www.itellyou.cn/
- AndroidStudio代码格式工具