stack
stack概述
stack是一种先进后出的数据结构。它只能有一个出口。stack允许新增元素、移除元素、取得最顶端元素。但除了最顶端元素外,没有任何其他方法可以存取stack的其他元素。换言之,stack不允许有遍历行为。
将新元素推入stack的操作称为push,将元素推出stack的操作称为pop。
stack定义完整列表
以某种既有容器作为底部结构,将其接口改变,使之符合“先进先出”的特性,形成一个stack,是很容易做到的。deque是双向开口的数据结构,若以deque为底部结构并封闭其头端开口,便轻而易举地形成一个stack。因此,SGI STL便以deque作为缺省情况下的stack底部结构 ,stack的实现因而非常简单,源代码十分简短。
template<class T, class Sequence = deque<T> >
class stack{
friend bool operator== __STL_NULL_TMPL_ARGS(const stack& , const stack&) ;
friend bool operator< __STL_NULL_TMPL_ARGS(const stack& , const stack&) ;
public :
typedef typename Sequence::value_type value_type ;
typedef typename Sequence::size_type size_type ;
typedef typename Sequence::reference reference ;
typedef typename Sequence::const_reference const_reference ;
protected