不多说,看代码

#include <iostream>
#include <vector>
#include <deque>
#include <list>
#include <forward_list>
#include "ContainerTest.h"
#include "ContainerUtil.h" using namespace std; void ContainerTest::run()
{
/*
1. vector test
*/ vector<int> coll;
for (int i = ; i <= ; ++i)
{
coll.push_back(i);
}
cout << "** print elements of vector **" << endl;
ContainerUtil<vector<int>>::printElements(coll); /*
2. deque test
*/ deque<int> coll2;
for (int i = ; i <= ; ++i)
{
coll2.push_front(i);
}
cout << "** print elements of deque **" << endl;
ContainerUtil<deque<int>>::printElements(coll2); /*
3. list test
*/ list<char> coll3;
for (char c = 'a'; c <= 'z';++c)
{
coll3.push_back(c);
}
cout << "** print elements of list **" << endl;
ContainerUtil<list<char>>::printElements(coll3);
cout << "print again:" << endl;
while (!coll3.empty())
{
cout << coll3.front() << ' ';
coll3.pop_front();
}
cout << endl; /*
4. forward list
*/ // create forward-list container for some prime numbers
forward_list<long> coll4 = { , , , , , , };
// resize two times
// - note: poor performance
coll4.resize();
coll4.resize(, );
cout << "** print elements of forward list **" << endl;
ContainerUtil<forward_list<long>>::printElements(coll4);
}

运行结果:

** print elements of vector **
  1  2  3  4  5  6
** print elements of deque **
  6  5  4  3  2  1
** print elements of list **
  a  b  c  d  e  f  g  h  i  j  k  l  m  n  o  p  q  r  s  t  u  v  w  x  y  z
print again:
a b c d e f g h i j k l m n o p q r s t u v w x y z
** print elements of forward list **
  2  3  5  7  11  13  17  0  0  99

STL - 常用顺序容器代码的更多相关文章

  1. STL - 常用关联容器代码 - set & multiset

    代码如下: /* 5. set & multiset */ set<string> cities{ "Braunschweig", "Hanover& ...

  2. STL常用序列容器

    这里简要的记述一下STL常用容器的实现原理,要点等内容. vector vector是比较常用的stl容器,用法与数组是非类似,其内部实现是连续空间分配,与数组的不同之处在于可弹性增加空间,而arra ...

  3. STL之顺序容器

    顺序容器: vector:数组 list:链表 deque:双端数组 顺序容器适配器: stack:堆栈 queue:队列 priority_queue:优先级队列 deque是一个动态数组 dequ ...

  4. STL之顺序容器 deque 动态数组

    deque是一个动态数组,deque与vector非常类似,vector是一个单向开口的连续线性空间,deque则是双向开口的连续线性空间.两者唯一的区别是deque可以在数组的开头和末尾插入和删除数 ...

  5. STL常用的容器

    vector:相当于一个不定长数组. vector的扩充机制是按照现在容量的一倍进行增长,每次增长是重新申请一块更大的心内存,并把现在容器中的元素逐个复制过去,然后销毁旧的内攒 1.头文件: #inc ...

  6. C++ 顺序容器基础知识总结

    0.前言 本文简单地总结了STL的顺序容器的知识点.文中并不涉及具体的实现技巧,对于细节的东西也没有提及.一来不同的标准库有着不同的实现,二来关于具体实现<STL源码剖析>已经展示得全面细 ...

  7. STL顺序容器【vector】【deque】【list】

    我们都知道,stl在集装箱船分为两类,订购集装箱和相关的容器. 顺序容器有三种即动态数组vector,双端队列deque,以及链表list (对csdn的文字排版严重吐槽.写好的版发表了就变了) 一: ...

  8. C++ STL常用容器浅析

    首先要理解什么是容器,在C++中容器被定义为:在数据存储上,有一种对象类型,它可以持有其它对象或指向其它对象的指针,这种对象类型就叫做容器.简单来说 容器就是包含其他类的对象们的对象,当然这种(容器) ...

  9. stl中顺序性容器,关联容器两者粗略解释

    什么是容器 首先,我们必须理解一下什么是容器,在C++ 中容器被定义为:在数据存储上,有一种对象类型,它可以持有其它对象或指向其它对像的指针,这种对象类型就叫做容器.很简单,容器就是保存其它对象的对象 ...

随机推荐

  1. python解决组合问题

    1.问题描述 比如9个数中取4个数的组合以及列出各种组合,该如何做? 我们可以考虑以下一个简单组合:从1,2,3,4,5,6中,如何选取任意四个数的组合. 固定:1   2  3  ,组合有1234 ...

  2. 【BZOJ 1566】 1566: [NOI2009]管道取珠 (DP)

    1566: [NOI2009]管道取珠 Time Limit: 20 Sec  Memory Limit: 650 MBSubmit: 1659  Solved: 971 Description In ...

  3. Navicat连接Docker中的mysql报错:client does not support authentication

    1.进入mysql容器中 docker exec -it mysqltest(mysql容器名称) bash 2.进入mysql数据库 mysql -uroot -p 3.输入mysql密码 4.远程 ...

  4. bzoj 2440

    题意:有一个从小到大的由不包含平方约数的数组成的数列,从1开始,求第k项. “满足某种限制的数的第k个”+二分答案="前n个数有多少个数满足限制“ 求[1,n]中有多少个数没有平方约数,我们 ...

  5. hdu 3507 斜率优化

    我的第一道斜率优化. 就这道题而言,写出原始的方程: dp[i] = min{ dp[j] + (sum[i]-sum[j])2  + M | j in [0,i) } O(n^2)的复杂度肯定超时, ...

  6. 【原创】Eclipse中Android项目引用

    1.选择名为SMSSDK的项目,右键--->Properties--->Android--->将Is Library勾上--->OK. 2.选中另一个名为FragmentDem ...

  7. Codeforces Round #262 (Div. 2) E. Roland and Rose 暴力

    E. Roland and Rose Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/pro ...

  8. 安装完Framework后如何不重启系统?

    在.net平台下客户端部署时,如果客户端没有安装Framework时,部署程序安装Framework后,有一个要求重启选项,当然是非强制的.如果不想出现这个提示“重启”选项,可以做如下选择: 1.启动 ...

  9. DCI:The DCI Architecture: A New Vision of Object-Oriented Programming

    SummaryObject-oriented programming was supposed to unify the perspectives of the programmer and the ...

  10. Unity3D协程介绍 以及 使用

    作者ChevyRay ,2013年9月28日,snaker7译  原文地址:http://unitypatterns.com/introduction-to-coroutines/ 在Unity中,协 ...