容器 迭代器
来源:互联网 发布:兵棋推演软件 编辑:程序博客网 时间:2024/06/16 05:17
STL包括: 容器(数据结构) 迭代器(遍历数据) 算法
顺序容器: vector(矢量) list(链表) deque(双端队列)
关联容器:set(集合) multist , map(映射),multimap
迭代器:类似于指针 用来访问容器中的单个数据项
迭代器由类iterator来声明。#include<iostream>
#include <algorithm>#include <vector>
using namespace std;
struct student
{
int numer;
char name[20];
float score;
};
bool comper(student s1, student s2)
{
return s1.score < s2.score;
}
int main()
{
student s1{ 10000,"张三",78.9 }, s2{ 10001,"王武",98.0 }, s3{ 10002,"李四",78.2 }, \
s4{ 10003,"李思思",99.0 }, s5{ 10004,"焦豆豆",60.0 }, s6{10005,"张飞",88.4};
vector<student> vt;
vt.push_back(s1);
vt.push_back(s2);
vt.push_back(s3);
vector<student>::iterator vi;
vi = vt.begin();
vi = vt.insert(vi,s4);
vi = vt.insert(vi,s5);
vt.insert(vi,s6);
for (vi = vt.begin(); vi != vt.end(); vi++)
cout << vi->numer << '\t' << vi->name <<'\t'<<vi->score << endl;
cout << "----------排序后-------------" << endl;
sort(vt.begin(),vt.end(),comper);
for (vi = vt.begin(); vi != vt.end(); vi++)
cout << vi->numer << '\t' << vi->name << '\t' << vi->score << endl;
system("pause");
return 0;
}
阅读全文
0 0
- 容器 迭代器
- 顺序容器--容器库.迭代器
- Qt的容器类之容器,迭代器
- c++容器无关迭代器
- 容器的迭代器
- 容器的迭代器
- 容器与迭代器 速记
- 容器与迭代器
- C++容器与迭代器
- 容器迭代器操作
- 容器迭代器失效问题
- vector容器类、迭代器
- C++容器 和迭代器
- C++容器 和迭代器
- 容器和迭代器
- C++容器/迭代器
- 理解容器和迭代器
- 【STL容器学习】-迭代器
- PAT甲级 1043
- greendao插入数据UNIQUE constraint failed: PURCHASE_ORDER_TABLE._id (code 1555)
- VLAN原理解释
- Java基本数据类型の字符型
- hdu 4460 Friend Chains # 最短路的最大值
- 容器 迭代器
- MySQL日期时间函数
- dubbo2.5.3消费dubbox提供的服务报错
- tomcat配置的项目总是出现卡死的现象
- 处理html字符串符合json
- 索引深入理解索引提高查询速度的原因
- 小谈CSRF
- Python3zip压缩解压简单使用
- C语言中time函数和localtime获取系统时间和日期