vector swap
#include <iostream>
#include <vector>
#include <list>
#include <deque>
using namespace std;
int main()
{
vector<int> a;
vector<int> b;
a.push_back(10);
a.push_back(20);
a.push_back(30);
a.push_back(40);
b.push_back(100);
b.push_back(200);
b.push_back(300);
vector<int>::iterator a_iter;
vector<int>::iterator b_iter;
for (a_iter =a.begin();a_iter !=a.end();a_iter++)
{
cout << *a_iter<< endl;
}
cout << "-------------------------------" << endl;
for (b_iter = b.begin(); b_iter != b.end(); b_iter++)
{
cout << *b_iter << endl;
}
cout << "-------------------------------" << endl;
a.swap(b);
vector<int>::iterator a_iter2;
vector<int>::iterator b_iter2;
for (a_iter2 = a.begin(); a_iter2 != a.end(); a_iter2++)
{
cout << *a_iter2 << endl;
}
cout << "-------------------------------" << endl;
for (b_iter2 = b.begin(); b_iter2 != b.end(); b_iter2++)
{
cout << *b_iter2 << endl;
}
cout << "-------------------------------" << endl;
system("pause");
return 0;
}
====================================================
10
20
30
40
-------------------------------
100
200
300
-------------------------------
100
200
300
-------------------------------
10
20
30
40
-------------------------------
请按任意键继续. . .
vector swap的更多相关文章
- 实战c++中的vector系列--正确释放vector的内存(clear(), swap(), shrink_to_fit())
关于vector已经写的差不多了,似乎要接近尾声了,从初始化到如何添加元素再到copy元素都有所涉及,是时候谈一谈内存的释放了. 是的,对于数据量很小的vector,完全没必要自己进行主动的释放,因为 ...
- c++ vector 使用
1. 包含一个头文件: 1 #include <vector> 2. 申明及初始化: std::vector<int> first; // empty vector of in ...
- vector容器删除某些元素且释放内存
1,size和capacity size: 指目前容器中实际有多少元素,对应的resize(size_type)会在容器尾添加或删除一些元素,来调整容器中实际的内容,使容器达到指定的大小. capac ...
- STL学习二:Vector容器
1.Vector容器简介 vector是将元素置于一个动态数组中加以管理的容器. vector可以随机存取元素(支持索引值直接存取, 用[]操作符或at()方法,这个等下会详讲). vector尾部添 ...
- vector 内部方法大全 学习(初学者的参考资料)
1 vector构造函数:也就是如何对一个vector对象进行初始化 ////////////////////////////代码//////////////////////////////// ...
- STL学习系列二:Vector容器
1.Vector容器简介 vector是将元素置于一个动态数组中加以管理的容器. vector可以随机存取元素(支持索引值直接存取, 用[]操作符或at()方法,这个等下会详讲). vector尾部添 ...
- vector的用法总结
Reference Constructors vector Constructs a vector of a specific size or with elements of a specific ...
- vector的成员函数解析
vector是线性容器,它的元素严格的依照线性序列排序,和动态数组非常相似,和数组一样,它的元素存储在一块连续的存储空间中,这也意味着我们不仅能够使用迭代器(iterator)訪问元素,还能够使用指针 ...
- vector成员函数解析
vector线性集装箱,其元素颜格排序根据线性序列,和动态数组很阶段似,像阵列,它的元素被存储在连续的存储空间,这也意味着,我们不仅能够使用迭代器(iterator)访问元素,也可以用一个指针访问偏移 ...
随机推荐
- Java与CC++交互JNI编程
哈哈,经过了前面几个超级枯燥的C.C++两语言的基础巩固之后,终于来了到JNI程序的编写了,还是挺不容易的,所以还得再接再厉,戒骄戒躁,继续前行!! 第一个JNI程序: JNI是一种本地编程接口.它允 ...
- SmtpClient 发送邮件
利用SmtpClient 代码发送邮件. 简单测试代码: static void Main(string[] args) { MailMessage msg = new MailMessage(); ...
- vue 之 render 函数不能渲染非全局自定义函数-方案
import customCom from 'xxx.vue' render: (h) => { return h(customCom) }
- JSONP劫持
发出空refer的POC <!DOCTYPE html> <html> <head> <meta name="referrer" cont ...
- CCPC 2016 杭州 E. Master of Subgraph(点分治+bitset优化DP)
题目链接:http://acm.hdu.edu.cn/downloads/CCPC2018-Hangzhou-ProblemSet.pdf 题意:给定一棵有 n 个结点的树和一个数 m,对于 i ∈ ...
- PHP mysqli_error() 函数
返回最近调用函数的最后一个错误描述: <?php // 假定数据库用户名:root,密码:123456,数据库:RUNOOB $con=mysqli_connect("localh ...
- MySQL Data Directory -- Creating file-per-table tablespaces outside the data directory
Creating file-per-table tablespaces outside the data directory 一. Data Directory 1.应对情况 当数据库所在空间不足的时 ...
- Python常用知识
基础模板(sys.os) http://c.biancheng.net/view/2407.html cmd中查看第三方库 eg:import aiohttp help(aiohttp) 或者dir( ...
- java集合类-List接口
List接口包含List接口及List接口的所有实现类,List集合中的元素允许重复. List接口 List接口继承了Collection接口,包含Collection接口的所有方法,还定义了两个非 ...
- openpyxl -用于读/写Excel 2010 XLSX/XLSM文件的python库
openpyxl -用于读/写Excel 2010 XLSX/XLSM文件的python库¶ https://www.osgeo.cn/openpyxl/index.html