STL_算法_逆转(reverse,reverse_copy)
C++ Primer 学习中。。
。
简单记录下我的学习过程 (代码为主)
//全部容器适用
reverse(b,e) //逆转区间数据
reverse_copy(b,e,b2)
/**------http://blog.csdn.net/u010579068------**/
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<deque>
#include<algorithm>
using namespace std; /*****************************************
//全部容器适用
reverse(b,e) //逆转区间数据
reverse_copy(b,e,b2)
*****************************************/
/**----------------------------------------------------------------------------------
STL算法 - 变序性算法 reverse() //逆转
reverse_copy()
rotate() //旋转
rotate_copy()
next_permutation()
prev_permutation()
random_shuffle()
partition()
stable_partition()
----------------------------------------------------------------------------------**/
/*************************************************************************************
std::reverse 全部排序容器适用 algorithm
--------------------------------------------------------------------------------------
<algorithm>template <class BidirectionalIterator>
void reverse ( BidirectionalIterator first, BidirectionalIterator last); //eg:
template <class BidirectionalIterator>
void reverse ( BidirectionalIterator first, BidirectionalIterator last)
{
while ((first!=last)&&(first!=--last))
swap (*first++,*last);
}
*************************************************************************************/ /*************************************************************************************
std::reverse_copy 全部排序容器适用 algorithm
--------------------------------------------------------------------------------------
template <class BidirectionalIterator, class OutputIterator>
OutputIterator reverse_copy ( BidirectionalIterator first,
BidirectionalIterator last, OutputIterator result );
//eg:
template <class BidirectionalIterator, class OutputIterator>
OutputIterator reverse_copy ( BidirectionalIterator first,
BidirectionalIterator last, OutputIterator result )
{
while (first!=last) *result++ = *--last;
return result;
}
*************************************************************************************/ int main()
{
vector<int> myvector;
vector<int>::iterator it; // set some values:
for (int i=1; i<10; ++i) myvector.push_back(i); // 1 2 3 4 5 6 7 8 9 reverse(myvector.begin(),myvector.end()); // 9 8 7 6 5 4 3 2 1 // print out content:
cout << "myvector contains:";
for (it=myvector.begin(); it!=myvector.end(); ++it)
cout << " " << *it;
cout << endl; int myints[] = {1,2,3}; cout << "The 3! possible permutations with 3 elements:\n"; sort (myints,myints+3);
reverse (myints,myints+3); do {
cout << myints[0] << " " << myints[1] << " " << myints[2] << endl;
} while ( prev_permutation (myints,myints+3) ); /**-------------------------------------------------------------------------------------**/
// int myints[] = {1,2,3,4,5,6,7,8,9};
deque<int> mydeque;
deque<int>::iterator iq; mydeque.resize(9); reverse_copy (myvector.begin(), myvector.end(), mydeque.begin()); // print out content:
cout << "mydeque contains:";
for (iq=mydeque.begin(); iq!=mydeque.end(); ++iq)
cout << " " << *iq;
cout << endl; return 0;
}
STL_算法_逆转(reverse,reverse_copy)的更多相关文章
- cb46a_c++_STL_算法_逆转和旋转reverse_rotate函数advance
cb46a_c++_STL_算法_逆转和旋转reverse_rotateSTL算法--变序性算法reverse() 逆转reverse_copy()一边复制一般逆转rotate()旋转,某个位置开始前 ...
- STL_算法_中使用的函数对象
写在前面: STL算法中的 函数对象的功能: (1).都是提供一种比较的函数,比较相邻的左右两个值的 相等/大小 等的关系, (2).返回值都是bool :该返回值 貌似是指明 遍历元素是否还要继续往 ...
- STL_算法_查找算法(lower_bound、upper_bound、equal_range)
C++ Primer 学习中. .. 简单记录下我的学习过程 (代码为主) //全部容器适用(O(log(n))) 已序区间查找算法 lower_bound() //找第一个符合的 ...
- STL_算法_查找算法(find、find_if)
C++ Primer 学习中. .. 简单记录下我的学习过程 (代码为主) find . find_if /**********************线性查找O(n) find(); find_if ...
- STL_算法_依据第n个元素排序(nth_element)
C++ Primer 学习中... 简单记录下我的学习过程 (代码为主) //全部容器适用 nth_element(b,n,e) nth_element(b,n,e,p) 对照:partition() ...
- STL_算法_查找算法(binary_search、includes)
C++ Primer 学习中.. . 简单记录下我的学习过程 (代码为主) 全部容器适用(O(log(n))) 已序区间查找算法 binary_search //二分查 ...
- STL_算法_局部排序(partial_sort、partial_sort_copy)
C++ Primer 学习中. . . 简单记录下我的学习过程 (代码为主) /***************************************** // partial_sort(b, ...
- STL_算法_区间的比較(equal、mismatch、 lexicographical_compare)
C++ Primer 学习中.. . 简单记录下我的学习过程 (代码为主) //全部容器适用 equal(b,e,b2) //用来比較第一个容器[b,e)和第二个容器b2开头,是否相等 e ...
- STL_算法_最小值和最大值(min_element、max_element)
C++ Primer 学习中... 简单记录下我的学习过程 (代码为主) min_element.max_element 找最小.最大值. 非常easy没什么大作用 #include<iost ...
随机推荐
- 深入理解async和await的作用及各种适用场景和用法
https://www.cnblogs.com/yaopengfei/archive/2018/07/02/9249390.html https://www.cnblogs.com/xianyudot ...
- Ubuntu 系统的常用快捷键
Ubuntu操作基本快捷键 ibus-setup :设置系统输入法 scp filename username@serverIp:/home/xxx/xxx/filename 回车输入该usern ...
- Python3之切片的道理
list的切片有三个参数:起点,终点,步长 list[::-1] 相当于起点为最后的一个,终点为第一个,然后一次减少一个 更多的看下面的测试 >>> a = [0,1,2,3,4,5 ...
- spring编程框架
spring boot, spring data, spring framework spring / spring boot @Profile('prod'|'dev'|'other')(伴随@Be ...
- XML——读与写
XML写入 private static void writeXml() { using (XmlTextWriter xml = new XmlTextWriter(@"C:\Users\ ...
- TCP:三次握手,URG、ACK、PSH、RST、SYN、FIN 含义
http://blog.csdn.net/wudiyi815/article/details/8505726 TCP:SYN ACK FIN RST PSH URG简析 三次握手Three-way ...
- Makefile精髓篇【转】
什么是makefile?或许非常多Winodws的程序猿都不知道这个东西,由于那些Windows的IDE都为你做了这个工作,但我觉得要作一个好的和professional的程序猿,makefile还是 ...
- CentOS6.9下NFS配置说明(转载)
NFS是Network File System的缩写,即网络文件系统.它的主要功能是通过网络(一般是局域网)让不同的主机系统之间可以共享文件或目录.NFS客户端可以通过挂载(mount)的方式将NFS ...
- DOClever线下部署安装说明文档
先本地要安装node环境,推荐6.10.0版本 到nodejs官网进行下载window版本进行安装,这里就不做说明了 接下来我们开始安装mongodb,首先下载mongodb 下载完成后我们一路 ...
- [测试工具]----iperf
iperf https://sourceforge.net/projects/iperf/ http://downloads.es.net/pub/iperf/ https://github.com/ ...