STL algorihtm算法iter_swap(29)
iter_swap原型:
std::iter_swap
template <class ForwardIterator1, class ForwardIterator2>
void iter_swap (ForwardIterator1 a, ForwardIterator2 b);
交换两个迭代器指向的元素的值。
该函数调用swap来交换两个值。
其行为类似与:
|
|
一个简单的样例:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(int argv,char **argc)
{
vector<int> v1{1,2,3,4};
vector<int> v2{10,11,20};
cout<<"v1=";
for(int i:v1)
cout<<i<<" ";
cout<<endl; iter_swap(v1.begin(),v1.end()-1);
cout<<"afeter iter_swap(v1.begin(),v1.end()-1);\n v1=";
for(int i:v1)
cout<<i<<" ";
cout<<endl; cout<<"v2=";
for(int i:v2)
cout<<i<<" ";
cout<<endl; iter_swap(v1.begin(),v2.end()-1);
cout<<"afeter iter_swap(v1.begin(),v2.begin());\n v1=";
for(int i:v1)
cout<<i<<" ";
cout<<endl; cout<<"v2=";
for(int i:v2)
cout<<i<<" ";
cout<<endl; }
执行截图:
——————————————————————————————————————————————————————————————————
//写的错误或者不好的地方请多多指导,能够在以下留言或者点击左上方邮件地址给我发邮件,指出我的错误以及不足。以便我改动。更好的分享给大家。谢谢。
转载请注明出处:http://blog.csdn.net/qq844352155
author:天下无双
Email:coderguang@gmail.com
2014-9-17
于GDUT
——————————————————————————————————————————————————————————————————
STL algorihtm算法iter_swap(29)的更多相关文章
- C++复习:STL之算法
算法 1算法基础 1.1算法概述 算法部分主要由头文件<algorithm>,<numeric>和<functional>组成. <algorithm> ...
- STL所有算法简介 (转) http://www.cnblogs.com/yuehui/archive/2012/06/19/2554300.html
STL所有算法简介 STL中的所有算法(70个) 参考自:http://www.cppblog.com/mzty/archive/2007/03/14/19819.htmlhttp://hi.baid ...
- 初探STL之算法
算法 STL算法部分主要由头文件<algorithm>,<numeric>,<functional>组成.要使用 STL中的算法函数必须包括头文件<algor ...
- stl变易算法(三)
本篇接着前面stl变易算法(一)和stl变易算法(二)继续讲述变易算法. 这里将介绍完余下的变易算法,主要有:填充fill.n次填充fill_n.随机生成元素generate.随机生成n个元素gene ...
- 常用的STL查找算法
常用的STL查找算法 <effective STL>中有句忠告,尽量用算法替代手写循环:查找少不了循环遍历,在这里总结下常用的STL查找算法: 查找有三种,即点线面: 点就是查找目标为单个 ...
- 【STL】帮你复习STL泛型算法 一
STL泛型算法 #include <iostream> #include <vector> #include <algorithm> #include <it ...
- STL基础--算法(排序)
STL排序算法 排序算法要求随机访问迭代器 vector, deque, container array, native array 例子 vector<int> vec = {9,1,1 ...
- [C++ STL] 常用算法总结
1 概述 STL算法部分主要由头文件<algorithm>,<numeric>,<functional>组成.要使用 STL中的算法函数必须包含头文件<alg ...
- STL中算法
sort 大数据量时,采用Quick Sort,分段递归排序: 小数据量时,采用Insert Sort. 如果迭代层次过深,会导致快排性能退化,这时采用Heap Sort排序. 快排pivot采用三点 ...
随机推荐
- css3 背景图动画一
一 实现背景图循环播放 @keyframes mlfly { 0%{ background-position:0 0; } 100%{ background-position:210px 0; } } ...
- 快充 IC BQ25896 的 ICO (input current optimizer)
ICO (input current optimizer) 手機接上 adapter 後, 手機裡的 charger IC bq25896 開始向 adapter 抽取 current 供給 batt ...
- 我的js为什么会触发两次
$(function() { $(".show").off("click").on("click",function(e){ e.preve ...
- L2-3. 悄悄关注【STL+结构体排序】
L2-3. 悄悄关注 时间限制 150 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 新浪微博上有个“悄悄关注”,一个用户悄悄关注的人,不出现在 ...
- UvaLive 4287 Proving Equivalences 强连通缩点
原题链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- bubble chat listview
最近在iOS中用到bubble chat listview,找了个比较有名气的lib(MessagesTableViewController)=>https://github.com/jesse ...
- Android 实现Activity后台运行
有时需要让activity在后台运行,具体实现方法如下: 在AndroidManifest.xml中,activity属性中增加: android:theme="@style/Backgro ...
- xamarin studio 安装
公司wpf项目移植到mac,用到mono来进行重写,不会,自己开搞 首先一个问题Xamarin怎么读,xaml熟悉吧,xaml读作Zamel,xamarin也就读作Zamerin,恩,就是它了... ...
- [反汇编练习] 160个CrackMe之031
[反汇编练习] 160个CrackMe之031. 本系列文章的目的是从一个没有任何经验的新手的角度(其实就是我自己),一步步尝试将160个CrackMe全部破解,如果可以,通过任何方式写出一个类似于注 ...
- Majority Number
题目描写叙述 链接地址 解法 算法解释 题目描写叙述 Given an array of integers, the majority number is the number that occurs ...