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)的更多相关文章

  1. cb46a_c++_STL_算法_逆转和旋转reverse_rotate函数advance

    cb46a_c++_STL_算法_逆转和旋转reverse_rotateSTL算法--变序性算法reverse() 逆转reverse_copy()一边复制一般逆转rotate()旋转,某个位置开始前 ...

  2. STL_算法_中使用的函数对象

    写在前面: STL算法中的 函数对象的功能: (1).都是提供一种比较的函数,比较相邻的左右两个值的 相等/大小 等的关系, (2).返回值都是bool :该返回值 貌似是指明 遍历元素是否还要继续往 ...

  3. STL_算法_查找算法(lower_bound、upper_bound、equal_range)

    C++ Primer 学习中. .. 简单记录下我的学习过程 (代码为主) //全部容器适用(O(log(n)))    已序区间查找算法 lower_bound()        //找第一个符合的 ...

  4. STL_算法_查找算法(find、find_if)

    C++ Primer 学习中. .. 简单记录下我的学习过程 (代码为主) find . find_if /**********************线性查找O(n) find(); find_if ...

  5. STL_算法_依据第n个元素排序(nth_element)

    C++ Primer 学习中... 简单记录下我的学习过程 (代码为主) //全部容器适用 nth_element(b,n,e) nth_element(b,n,e,p) 对照:partition() ...

  6. STL_算法_查找算法(binary_search、includes)

    C++ Primer 学习中.. . 简单记录下我的学习过程 (代码为主) 全部容器适用(O(log(n)))     已序区间查找算法 binary_search             //二分查 ...

  7. STL_算法_局部排序(partial_sort、partial_sort_copy)

    C++ Primer 学习中. . . 简单记录下我的学习过程 (代码为主) /***************************************** // partial_sort(b, ...

  8. STL_算法_区间的比較(equal、mismatch、 lexicographical_compare)

    C++ Primer 学习中.. . 简单记录下我的学习过程 (代码为主) //全部容器适用 equal(b,e,b2)       //用来比較第一个容器[b,e)和第二个容器b2开头,是否相等 e ...

  9. STL_算法_最小值和最大值(min_element、max_element)

    C++ Primer 学习中... 简单记录下我的学习过程 (代码为主) min_element.max_element  找最小.最大值. 非常easy没什么大作用 #include<iost ...

随机推荐

  1. [转]Android的userlogin登录

    本文转自:http://hteqc6o.blog.sohu.com/199334086.html 用户注册 1.首先,先画你想要编译出的界面 根据草图,仅仅使用linearLayout的布局是不够的, ...

  2. 软件图标显示不正常【win7企业版】

    现象: 原因: 图标缓存没有把该软件图标建立起来 解决: 一. 1.找到 IconCache.db 2.你要把电脑隐藏文件打开不然找不到这个文件的,组织—文件夹及搜索选项——查看——显示隐藏文件.文件 ...

  3. 项目管理01--使用Maven构建项目(纯干货)

    目录 1. Maven基础知识 2. Maven实战.开发.测试.打包.部署一个Web项目 一.Maven基础知识 Maven坐标 Maven提供了一个中央仓库,里面包含了大量的开源软件的jar包,只 ...

  4. 关于 WebView 的一些笔记

    什么是 WebView WebView 是手机中内置了一款高性能 webkit 内核浏览器,在 SDK 中封装的一个组件.没有提供地址栏和导航栏, WebView 只是单纯的展示一个网页界面.在开发中 ...

  5. Tcl之looping

    1 While loop while test body The while command evaluates test as an expression. If test is true, the ...

  6. ProE常用曲线方程:Python Matplotlib 版本代码(蝴蝶曲线)

    花纹的生成可以使用贴图的方式,同样也可以使用方程,本文列出了几种常用曲线的方程式,以取代贴图方式完成特定花纹的生成. 注意极坐标的使用................. 前面部分基础资料,参考:Pyt ...

  7. Objective-C在ARC下结合GCD的单例模式和宏模版

    单例模式在iOS开发过程中经常用到,苹果提供过objective c单例的比较官方的写法: static MyGizmoClass *sharedGizmoManager = nil; + (MyGi ...

  8. python笔记之发送邮件

    发送邮件前提:开启邮箱授权码 一.开启授权码(以163邮箱为例) 1.登录163邮箱,点击设置--POP3/SMTP/IMAP,出现设置界面   2. 开启SMTP服务且可以查询SMTP的host地址 ...

  9. chrome浏览器处理本地Ajax跨域

    chrome浏览器下 项目开发过程中,用到了Ajax异步请求.若将项目放在本地服务器中,通过localhost访问文件,不会报错.若直接通过file://访问文件就会报错. 报错信息: XMLHttp ...

  10. 水图(牛客练习赛(DFS搜索))

    题意: 小w不会离散数学,所以她van的图论游戏是送分的 小w有一张n个点n-1条边的无向联通图,每个点编号为1~n,每条边都有一个长度小w现在在点x上她想知道从点x出发经过每个点至少一次,最少需要走 ...