不多说,看代码

#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. RabbitMQ (一)

    学习RabbitMQ 可以先先了解一下AMQP 简单介绍: AMQP从一开始就设计成为开放标准,以解决众多的消息队列需求和拓扑结构问题,凭借开发,任何人都可以执行这一标准.针对标准编码的任何人都可以和 ...

  2. BZOJ1030 [JSOI2007]文本生成器(AC自动机)

    做到了AC自动机的题目,复习了一下AC自动机,学习了黄学长代码,这个题呢,我们可以模拟在AC自动机上的操作,dp数组f[i][j]表示前i个字符,我们在AC自动机上处在j号节点的方案数. 我们可以计算 ...

  3. NOIP2017 D1T1小凯的疑惑

    这应该是近年来最坑的第一题了. 我第一眼看到这题上来就打表,数据范围告诉我复杂度应该是log级的,然而一个小时后才发现是一个输出结论. 设较小数是a 较大数是b 写出几组可以发现一个规律就是一旦出现连 ...

  4. hibernate核心及常用技术

    一.hibernate介绍 1.hibernate概述 hibernate是轻量级Java EE持久层解决方案,管理java类到数据库表的映射(ORM:对象关系型数据映射),并提供数据查询获取的方法. ...

  5. hdu 1561 树形dp+分组背包

    题意:就是给定n个点,每个地点有value[i]的宝物,而且有的宝物必须是另一个宝物取了才能取,问取m个点可以获得的最多宝物价值. 一个子节点就可以返回m个状态,每个状态表示容量为j(j<=m) ...

  6. WampServer -- “You don't have permission to access /phpmyadmin/ on this server.”

    当你安装完成wamp后,打开localhost或ip时发现已经可以运行了 但想使用phpmyadmin时,发现提示如下内容: You don't have permission to access / ...

  7. When to use static method in a java class

    First , please understand its feature : * no need to instantiate a instance, i.e. simply you can jus ...

  8. php获取开始与结束日期之间所有日期的方法

    /** * 获取指定日期段内每一天的日期 * @param Date $startdate 开始日期 * @param Date $enddate 结束日期 * @return Array */ fu ...

  9. Dual-polarity supply provides ±12V from one IC

    LT1961 升压型稳压器造就了兼具升压和降压能力的扁平状SEPIC Transformerless dc/dc converter produces bipolar outputs Well-reg ...

  10. Springboot集成Jedis + Redisson(已自测)

    原文:https://blog.csdn.net/c_zyer/article/details/79415728 本文主要跟大家分享在Springboot中集成Jedis和Redisson的方法.为什 ...