STL - vector algorithm
// create vector with elements from 1 to 6 in arbitrary order
vector<int> coll = { , , , , , }; // find and print minimum and maximum elements
auto minpos = min_element(coll.cbegin(), coll.cend());
cout << "min: " << *minpos << endl;
auto maxpos = max_element(coll.cbegin(), coll.cend());
cout << "max: " << *maxpos << endl; cout << "original vector:" << endl;
ContainerUtil<vector<int>>::printElements(coll);
// sort all elements
sort(coll.begin(), coll.end());
cout << "after sorting:" << endl;
ContainerUtil<vector<int>>::printElements(coll); // find the first element with value 3
// - no cbegin()/cend() because later we modify the elements pos3 refers to
auto pos3 = find(coll.begin(), coll.end(), ); // reverse the order of the found element with value 3 and all following elements
reverse(pos3, coll.end());
cout << "after reverse from the position of value 3:" << endl;
ContainerUtil<vector<int>>::printElements(coll);
运行结果:
min: 1
max: 6
original vector:
2 5 4 1 6 3
after sorting:
1 2 3 4 5 6
after reverse from the position of value 3:
1 2 6 5 4 3
STL - vector algorithm的更多相关文章
- C++ STL vector容器学习
STL(Standard Template Library)标准模板库是C++最重要的组成部分,它提供了一组表示容器.迭代器.函数对象和算法的模板.其中容器是存储类型相同的数据的结构(如vector, ...
- STL vector用法介绍
STL vector用法介绍 介绍 这篇文章的目的是为了介绍std::vector,如何恰当地使用它们的成员函数等操作.本文中还讨论了条件函数和函数指针在迭代算法中使用,如在remove_if()和f ...
- STL vector+sort排序和multiset/multimap排序比较
由 www.169it.com 搜集整理 在C++的STL库中,要实现排序可以通过将所有元素保存到vector中,然后通过sort算法来排序,也可以通过multimap实现在插入元素的时候进行排序.在 ...
- STL vector 用法介绍
介绍 这篇文章的目的是为了介绍std::vector,如何恰当地使用它们的成员函数等操作.本文中还讨论了条件函数和函数指针在迭代算法中使用,如在remove_if()和for_each()中的使用.通 ...
- STL vector使用方法介绍
介绍 这篇文章的目的是为了介绍std::vector,怎样恰当地使用它们的成员函数等操作.本文中还讨论了条件函数和函数指针在迭代算法中使用,如在remove_if()和for_each()中的使用.通 ...
- C++STL vector详解(杂谈)
介绍 这篇文章的目的是为了介绍std::vector,如何恰当地使用它们的成员函数等操作.本文中还讨论了条件函数和函数指针在迭代算法中使用,如在remove_if()和for_each()中的使用.通 ...
- C++ stl vector介绍
转自: STL vector用法介绍 介绍 这篇文章的目的是为了介绍std::vector,如何恰当地使用它们的成员函数等操作.本文中还讨论了条件函数和函数指针在迭代算法中使用,如在remove_if ...
- STL vector
STL vector vector是线性容器,它的元素严格的按照线性序列排序,和动态数组很相似,和数组一样,它的元素存储在一块连续的存储空间中,这也意味着我们不仅可以使用迭代器(iterator)访问 ...
- stl——vector详解
stl——vector详解 stl——vector是应用最广泛的一种容器,类似于array,都将数据存储于连续空间中,支持随机访问.相对于array,vector对空间应用十分方便.高效,迭代器使ve ...
随机推荐
- Hibernate 基于外键的单项一对一关联映射
在开发过程中很多时候会用到表与表之间一对一的关联关系,本文简单介绍在Hibernate4中单项一对一的关联映射. 1.设计表结构 2.创建Person对象 3.创建IdCard对象 4.写hbm.xm ...
- 「POI2011 R1」Conspiracy
「POI2011 R1」Conspiracy 解题思路 : 问题转化为,将点集分成两部分,其中一部分恰好组成一个团,其中另一部分恰好组成一个独立集. 观察发现,如果求出了一个解,那么答案最多可以在这个 ...
- ( VIJOS )VOJ 1049 送给圣诞夜的礼品 矩阵快速幂
https://vijos.org/p/1049 非常普通的矩阵快速幂... 但是我 第一次写忘了矩阵不能交换律... 第一二次提交RE直到看到题解才发现这道题不能用递归快速幂... 第三次提交成 ...
- JNI介绍
JNI是在学习Android HAL时必须要面临一个知识点,如果你不了解它的机制,不了解它的使用方式,你会被本地代码绕的晕头转向,JNI作为一个中间语言的翻译官在运行Java代码的Android中有着 ...
- java开发_mysql中获取数据库表描述_源码下载
功能描述: 在mysql数据库中,有两张表: data_element_config , test_table 我们需要获取表:test_table表的描述信息,然后把描述信息插入到表:data_el ...
- hdu 5195 DZY Loves Topological Sorting 线段树+拓扑排序
DZY Loves Topological Sorting Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/sho ...
- 阻止a标签跳转
一.在html中 1. <a href="javascript:;"></a> 2. <a href="###">&l ...
- 几个未公开的 DBCC 命令
http://blog.csdn.net/CathySun118/article/category/538610 https://ask.hellobi.com/blog/lyhabc/1612 1. ...
- Git 报错:git - error: RPC failed; curl 18 transfer closed with outstanding read data remaining 解决方案
error: RPC failed; curl 18 transfer closed with outstanding read data remaining because have error w ...
- oracle维护服务 oracle解决方案 oracle售后服务
为客户提供的oracle 金牌技术服务内容为: 1.电话服务 (7*24) 热线支持电话800-810-0081 每周7天,每天24小时北京技术支持中心每天都有专人值守.以保证及时与客 ...