标签:style blog http color os io
本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie
stack
-------------------------------------------------------------#include <stack> #include <list> #include <iostream> #include <algorithm> using namespace std; int main(){ stack<int, list<int> >istack; istack.push(1); istack.push(2); cout << istack.size() << endl << istack.top() << endl; }
#ifndef __SGI_STL_INTERNAL_STACK_H #define __SGI_STL_INTERNAL_STACK_H __STL_BEGIN_NAMESPACE #ifndef __STL_LIMITED_DEFAULT_TEMPLATES template <class T, class Sequence = deque<T> > //默认以 deque 为底层容器 #else template <class T, class Sequence> #endif 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: Sequence c; //底层容器 public: //以下完全利用 Sequence c 的操作完成 stack 的操作 bool empty() const { return c.empty(); } size_type size() const { return c.size(); } reference top() { return c.back(); } const_reference top() const { return c.back(); } //修改接口使符合 stack "前进后出"的特性 void push(const value_type& x) { c.push_back(x); } void pop() { c.pop_back(); } }; template <class T, class Sequence> bool operator==(const stack<T, Sequence>& x, const stack<T, Sequence>& y) { return x.c == y.c; } template <class T, class Sequence> bool operator<(const stack<T, Sequence>& x, const stack<T, Sequence>& y) { return x.c < y.c; } __STL_END_NAMESPACE #endif /* __SGI_STL_INTERNAL_STACK_H */ // Local Variables: // mode:C++ // End:
STL源码剖析 容器 stl_stack.h,布布扣,bubuko.com
标签:style blog http color os io
原文地址:http://blog.csdn.net/zhengsenlie/article/details/38011219