C++ STL stack
来源:互联网 发布:淘宝店铺类目是什么 编辑:程序博客网 时间:2024/06/04 20:23
template <class T, class Container = deque<T> > class stack;
LIFO stack
Stacks are a type of container adaptor, specifically designed to operate in a LIFO context (last-in first-out), where elements are inserted and extracted only from one end of the container.stacks are implemented as containers adaptors, which are classes that use an encapsulated object of a specific container class as its underlying container, providing a specific set of member functions to access its elements. Elements are pushed/popped from the "back" of the specific container, which is known as the top of the stack.
The underlying container may be any of the standard container class templates or some other specifically designed container class. The container shall support the following operations:
- back
- push_back
- pop_back
The standard container classes vector, deque and list fulfill these requirements. By default, if no container class is specified for a particular stack class instantiation, the standard container deque is used.
#include "algostuff.hpp"
#include <iterator>#include <ostream>
#include <numeric>
#include <stack>
using namespace std;
int main(){
stack<int> st;
st.push(1);
st.push(2);
st.push(3);
cout<<st.top()<<' ';
st.pop();
cout<<st.top()<<' ';
st.pop();
st.top()=77;
st.push(4);
st.push(5);
st.pop();
while(!st.empty()){
cout<<st.top()<<' ';
st.pop();
}
cout<<endl;
return 1;
}
编译后输出:
3 2 4 77
0 0
- c++stl中的stack
- 【day0414 C++】STL stack 栈的使用
- c++STL之stack(堆栈)
- STL stack
- stl stack
- STL stack
- stl stack
- stl stack
- stL stack
- STL stack
- STL stack
- STL-stack
- STL-stack
- STL stack
- STL--stack
- STL stack
- STL STACK
- STL stack
- 反向LL(1)预测分析法的简易C++四则表达式计算
- iOS中的MVC
- Unity3d Static
- 【JAVA学习】Java中迭代器Iterator遍历的两种用法
- 关于C#作业计算器的一个突发奇想
- C++ STL stack
- codeforces_240_div1解题报告
- HDU 1867 A + B for you again(KMP:后缀与前缀)
- runtime exec
- Android中自定义Adapter的基本原理
- spring MVC配置详解
- Android之自定义Adapter的ListView
- Linux 下c语言ftp服务器简单实现
- C++ STL queue