MinStack
来源:互联网 发布:熊猫书院骗局知乎 编辑:程序博客网 时间:2024/06/05 01:02
#ifndef HEAD_#pragma comment(linker, "/STACK:36777216")#include <algorithm>#include <bitset>#include <cassert>#include <cmath>#include <cstdio>#include <cstring>#include <ctime>#include <functional>#include <iomanip>#include <iostream>#include <list>#include <map>#include <queue>#include <set>#include <stack>#include <string>#include <vector>#define cst constusing namespace std;#endif // HEAD_#ifndef TYPEDEFtypedef long long llint;typedef double lf;typedef unsigned uint;typedef unsigned long long ullint;#endif // TYPEDEFtemplate<class ElemType> class MinStack {private: stack<ElemType> data, minimum;public: void push(ElemType v) { data.push(v); if (minimum.empty()) minimum.push(v); else minimum.push(min(v, minimum.top())); } bool empty() { return data.empty(); } uint size() { return data.size(); } void pop() { assert(!data.empty()); data.pop(); minimum.pop(); } ElemType top() { return data.top(); } ElemType stackMin() { return minimum.top(); }};int main() { #ifndef ONLINE_JUDGE// freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout); #endif MinStack< int > ms; ms.push(11); ms.push(120); ms.push(7); cout << "top " << ms.top() << endl; cout << "size " << ms.size() << endl; ms.pop(); cout << "top " << ms.top() << endl; cout << "min " << ms.stackMin() << endl; return 0;}
0 0
- MinStack
- MinStack
- minStack
- MinStack
- MinStack
- leetcode-MinStack
- LEETCODE-MinStack
- leetcode155.MinStack
- 【单调队列】leetcode MinStack
- LeedCode—MinStack
- LeetCode155 MinStack java题解
- leetcode 第160题 MinStack
- LeetCode题解:MinStack(三种解法)
- 算法-最小栈的实现-minStack
- MinStack + Implement Queue using stacks = MinQueue
- python读文件open file 中文乱码问题
- 网页采集资料---有防采集的解决方法
- 【转】IOS隐藏键盘
- 添加微信tabbar中有消息的小红点
- delete this--对象请求自杀
- MinStack
- Segment Fault 的访问地址究竟在哪里?
- 只需要努力,其他的都交给时光----三级网络学习总结
- 企业服务总线ESB之概述
- 回车,换行
- 分布式搜索Elasticsearch——创建客户端(五)
- 实现UIScrollView的分页
- Eclipse 弹出 Failed to load the JNI shared library jvm.dll 错误的解决方法!
- Cocos2d-x教程(8)-遮罩层实现捕鱼达人滚动数字表盘