第13章 标准库中的容器.pptVIP

  • 10
  • 0
  • 约 44页
  • 2016-05-21 发布于湖北
  • 举报
13.12 容器适配器——stack 容器适配器stack表示先进后出的数据结构(栈)。之前曾经提到,标准库中容器适配器的代码并不是从零开始编写,而是适配某种序列容器。 容器适配器stack可以使用3种序列容器中的任意一种适配,默认使用deque。 程序13.9演示容器适配器stack的使用方法以及主要成员函数的使用。 1 //13.9 容器适配器stack 13 template class T 14 void push_pop_stack(T s,const char* str) 15 { cout.setf(ios::fixed); 17 T::value_type seed=T::value_type(); 18 for(int i=0;i5;++i) 19 s.push(++seed+64); 20 coutstr; 21 while(!s.empty()) 22 { couts.top() ; 24 s.pop(); 25 } 26 coutendl; 27 } 28 int main() 29 { 30 stackint s1; 31 push_pop_stack(s1,s1:); 32 33 stackdouble,vectordouble s2; 34 push_pop_sta

文档评论(0)

1亿VIP精品文档

相关文档