栈
来源:互联网 发布:电脑自带录屏软件 编辑:程序博客网 时间:2024/05/22 00:09
STL编程
#include <iostream>#include <stack>using namespace std;void InitStack(stack<int> &s, int n);void InitDest(stack<int> &s, int n);void InitStack(stack<int> &s, int n) //初始化原始数据栈{for (int i = n; i > 0; i--){s.push(i);}}void InitDest(stack<int> &s, int n) //初始化目的数据栈{int temp;for (int i = 0; i < n; i++){cin >> temp;s.push(temp);}}int main(){stack<int> SourceStack, TempStack, DestStack;int n, m;cin >> n >> m;InitStack(SourceStack, n);InitDest(DestStack, n);if (SourceStack == DestStack)cout << "Yes" << endl;elsecout << "No" << endl;return 0;}
全排列:列车调度
#include <iostream>#include <queue>#include <stack>using namespace std;bool IsPerm(int n);bool IsPerm(int n){ queue<int> QueueA; //A轨道列车 stack<int> Station; //中转站S bool ok=true; int i; for(i=1;i<=n;i++) { QueueA.push(i); ///将1,2,3,...,n的队列存在QueueA中 } for(i=0;i<n;i++) { int temp; cin>>temp; while(!QueueA.empty() && temp>=QueueA.front()) { Station.push(QueueA.front()); QueueA.pop(); } if(!Station.empty() && temp == Station.top()) { Station.pop(); //如果x在栈顶,则输出X } else { ok=false; while(++i<n) cin>>temp; break; } } return ok;}int main(){ int n; cin>>n; if(IsPerm(n)==true) cout<<"OK"<<endl; else cout<<"No"<<endl; return 0;}
0 0
- 栈
- 栈
- 栈
- 栈
- 栈
- 栈
- 栈
- 栈
- 栈
- 栈
- 栈
- 栈
- 栈
- 栈
- 栈
- 栈
- 栈
- 栈
- 背包·分组背包
- RFID系统信号通信过程
- 数据库学习笔记系列(3)——索引_2
- OSPF-LSA系列—LSA TYPE 4和5
- 消除 activity 启动时白屏、黑屏问题
- 栈
- OpenStack源码系列---nova-conductor
- org.hibernate.exception.GenericJDBCException: Could not open connection
- Apache Kafka中Follower如何与Leader同步数据
- C语言判断字符串是否为数字
- 关于并发的零碎知识
- 腾讯实习生面试
- Chrome 开发工具概述
- 队列的C语言实现