cb08a_c++_顺序容器的操作1
2024-10-09 07:23:46
cb08a_c++_顺序容器的操作1
容器定义的类型别名
begin(闭区间)和end(开区间)成员
{first,last)左闭右开,左包括,右不包括,end()指向最后一个的下一个。
/*cb08a_c++_顺序容器的操作1
容器定义的类型别名
begin(闭区间)和end(开区间)成员
{first,last)左闭右开,左包括,右不包括,end()指向最后一个的下一个。 */ #include <iostream>
#include <vector>
#include <list>
#include <deque>
using namespace std; int main()
{
vector<int> a; list<int> b; //链表没有下表,不能用数组表示
deque<int> c; //error C2663: “std::vector<int,std::allocator<_Ty>>::push_back”: 2 个重载没有“this”指针的合法转换
//ca.push_back(11);//const vector不能直接放数据 a.push_back();
a.push_back();
a.push_back();
const vector<int> ca(a);//const可以通过非const vector传入数据,进行初始化。类似于:ca=a; b.push_back();
b.push_back();
b.push_back(); c.push_back();
c.push_back();
c.push_back();
//for(int i=0;i<a.size();++i)//不要使用,因为int类型不够大,可能vector数据会超出。 for (vector<int>::size_type i = ; i < a.size(); ++i)
cout << a[i] << endl;
////链表没有下表,不能用数组表示
/*for (list<int>::size_type k = 0; k < b.size(); ++k)
cout << b[k] << endl;*/ for (deque<int>::size_type j = ; j < c.size(); ++j)
cout << c[j] << endl; //链表只能用迭代器
vector<int>::iterator firsta = a.begin();
vector<int>::iterator lasta = a.end();//end()指向最后一个的下一个 vector<int>::const_iterator cfirsta = ca.begin();//const_iterator,const迭代器,操作const vector容器
vector<int>::const_iterator clasta = ca.end(); while (firsta != lasta)
{
cout <<"迭代器循环: "<< *firsta << endl;
++firsta;
}
vector<int>::reverse_iterator rfirsta = a.rbegin();//rbegin()逆序迭代器
vector<int>::reverse_iterator rlasta = a.rend();//rend()逆序迭代器 vector<int>::size_type a1;
vector<int>::iterator a2;
vector<int>::const_iterator a3;
vector<int>::reverse_iterator a4;//逆序迭代器
vector<int>::const_reverse_iterator a5;
vector<int>::difference_type a6;//保存容器之间距离 //泛型程序设计
//vector<int>::value_type a7;
//vector<int>::reference a8;//引用
//vector<int>::const_reference a9; list<int>::size_type b1;
list<int>::iterator b2;
list<int>::const_iterator b3;
list<int>::reverse_iterator b4;
list<int>::const_reverse_iterator b5;
list<int>::difference_type b6;
/*list<int>::value_type b7;
list<int>::reference b8;
list<int>::const_reference b9;*/ deque<int>::size_type c1;
deque<int>::iterator c2;
deque<int>::const_iterator c3;
deque<int>::reverse_iterator c4;
deque<int>::const_reverse_iterator c5;
deque<int>::difference_type c6;
/*deque<int>::value_type c7;
deque<int>::reference c8;
deque<int>::const_reference c9;*/ cout << "hello..." << endl;
return ;
}
最新文章
- Beta版本冲刺——day7
- Java--接口和类集框架
- 支持异步通知的globalfifo平台设备驱动程序及其测试代码
- 2.5.3 使用alertDialog创建自定义对话框
- How to find friends
- javadoc 生成帮助文档时,注意以下几点
- div图片垂直居中
- Java 使用JDBC、DBCP、C3P0访问数据库
- Oracle 六闪回技术,flashback
- apk反汇编之smali语法
- ●POJ 2284 That Nice Euler Circuit
- iis .apk .ipa下载设置
- Shiro的认证授权
- POJ 1703 Find them, Catch them (并查集)
- 深度学习原理与框架-神经网络-cifar10分类(代码) 1.np.concatenate(进行数据串接) 2.np.hstack(将数据横着排列) 3.hasattr(判断.py文件的函数是否存在) 4.reshape(维度重构) 5.tanspose(维度位置变化) 6.pickle.load(f文件读入) 7.np.argmax(获得最大值索引) 8.np.maximum(阈值比较)
- Mysql 触发器 A表记录到B表
- javascript - return
- RK3288 查看时钟树
- 使用shell脚本往文件中加一列
- Selenium2+python自动化63-简易项目搭建【转载】