[c++] vector的使用
1 #include<iostream>
2 #include<vector>
3 using namespace std;
4
5 void print( vector<int> &vec )
6 {
7 for ( vector<int>::iterator it = vec.begin(); it!=vec.end(); it++ )
8 cout<<*it<<' ';
9 cout<<endl;
}
void push( vector<int> &vec, int value )
{
vec.push_back(value);
}
int main()
{
vector<int> first;
vector<int> second (,); // four ints with value 100
print(second);
vector<int> third ( second.begin()+, second.end() );
print(third);
vector<int> fourth (third);
//construct from arrays
int arrays[] = {,,,,,};
vector<int> fifth ( arrays, arrays + sizeof(arrays)/sizeof(int) );
print(fifth);
push(fifth, );
print(fifth);
fifth.pop_back();
print(fifth);
fifth.pop_back();
print(fifth);
cout<<"capacity is "<<fifth.capacity()<<endl;
cout<<"size is "<<fifth.size()<<endl;
fifth.reserve();
cout<<"capacity is "<<fifth.capacity()<<endl;
cout<<"size is "<<fifth.size()<<endl;
print(fifth);
// erase the first 3 elements:
fifth.erase(fifth.begin(), fifth.begin()+);
for (int i=; i<fifth.size(); i++ )
cout<<fifth[i]<<' ';
cout<<endl;
return ;
}
[c++] vector的使用的更多相关文章
- c++ vector 使用
1. 包含一个头文件: 1 #include <vector> 2. 申明及初始化: std::vector<int> first; // empty vector of in ...
- Vector Tile
Mapbox Vector Tile Specification A specification for encoding tiled vector data. <?XML:NAMESPACE ...
- ArrayList、Vector、LinkedList的区别联系?
1.ArrayList.Vector.LinkedList类都是java.util包中,均为可伸缩数组. 2.ArrayList和Vector底层都是数组实现的,所以,索引数据快,删除.插入数据慢. ...
- ArrayList、Vector、HashMap、HashSet的默认初始容量、加载因子、扩容增量
当底层实现涉及到扩容时,容器或重新分配一段更大的连续内存(如果是离散分配则不需要重新分配,离散分配都是插入新元素时动态分配内存),要将容器原来的数据全部复制到新的内存上,这无疑使效率大大降低. 加载因 ...
- Java中Vector和ArrayList的区别
首先看这两类都实现List接口,而List接口一共有三个实现类,分别是ArrayList.Vector和LinkedList.List用于存放多个元素,能够维护元素的次序,并且允许元素的重复.3个具体 ...
- C++使用vector
#include <iostream> #include <string> #include <vector> using namespace std; void ...
- [LeetCode] Flatten 2D Vector 压平二维向量
Implement an iterator to flatten a 2d vector. For example,Given 2d vector = [ [1,2], [3], [4,5,6] ] ...
- C++ 数组array与vector的比较
转:http://blog.csdn.net/yukin_xue/article/details/7391897 1. array 定义的时候必须定义数组的元素个数;而vector 不需要: 且只能包 ...
- vector定义初始化
头文件 #include<vector> using std::vector; vector<T> v1; vector<T> v2(v1); vector< ...
- vector迭代器用法
#include<iostream> #include<vector> using namespace std; int main() { vector<int> ...
随机推荐
- Linux 内核常见宏定义
我们在阅读Linux内核是,常见到这些宏 __init, __initdata, __initfunc(), asmlinkage, ENTRY(), FASTCALL()等等.它们定义在 /incl ...
- HTML5 History API 实现无刷新跳转
在HTML5中, 1. 新增了通过JS在浏览器历史记录中添加项目的功能. 2. 在不刷新页面的前提下显示改变浏览器地址栏中的URL. 3. 添加了当用户单击浏览器的后退按钮时触发的事件. 通过以上三 ...
- Hibernate2
计应134(实验班) 杨伟 Hibernate 中提供了两级Cache(高速缓冲存储器),第一级别的缓存是Session级别的缓存,它是属于事务范围的缓存.这一级别的缓存由hibernate管理的,一 ...
- Java JDBCI批量插入数据
智能插入:将整批分批,每一千条提交一次,sql注入(安全,使用软解析,提高效率) sql注入攻击:简单例子 select * from table where name='"+un+&quo ...
- ruby环境的配置
安装 Ruby 解析器 一些Linux发行版本,MacOSX操作系统都自带Ruby解析器,但是我仍然建议自行下载ruby源代码编译安装.因为一方面可以自己定制ruby安装的路径,另一方面可以在编译过程 ...
- 个人对sort()排序方法中比较函数一直很混乱,今日理清
需求:使用随机数来打印出0-10,并排序. 代码: var a = new Array();var testArray = function() { while (1) { var b = parse ...
- HTML5和CSS3的一些新特性
html5有哪些新特性.移除了那些元素?如何处理HTML5新标签的浏览器兼容问题?如何区分 HTML 和 HTML5? 新特性: 1. 拖拽释放(Drag and drop) 2. 语义化更好的内容标 ...
- liquibase的使用
前言 liquibase是一个数据库持续集成插件.独立于数据库存在,oracle,mysql,db2,h2,sql server,postgresql都能使用.它使用配置文件来更新数据库结构,并加入版 ...
- js⑤
##返回在制定位置的的字符 var result = str.charAt(1); console.log(result); console.log(str[1]); ##返回在指定的位置的字符 ...
- asp.net MVC code first Migrations : Model 同步到DB中
找来找去,看来用这个功能的人很少. http://www.it165.net/pro/html/201403/10653.html 步骤: 1,在程序包管理控制台上,Enable-Migrations ...