iter_swap原型:

std::iter_swap

template <class ForwardIterator1, class ForwardIterator2>
void iter_swap (ForwardIterator1 a, ForwardIterator2 b);

交换两个迭代器指向的元素的值。

该函数调用swap来交换两个值。

其行为类似与:

1
2
3
4
5
template <class ForwardIterator1, class ForwardIterator2>
void iter_swap (ForwardIterator1 a, ForwardIterator2 b)
{
swap (*a, *b);
}

一个简单的样例:

#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

——————————————————————————————————————————————————————————————————


最新文章

  1. html中用div代替textarea实现输入框高度随输入内容变化
  2. 【ionic】Mac IOS下真机调试
  3. 【翻译】hololens入门
  4. CPU相关知识-寄存器与存储器的区别
  5. Myeclipse-导入spring
  6. [开发笔记]-jQuery获取checkbox选中项等操作及注意事项
  7. 使用git对unity3d项目进行版本控制
  8. hdu 4679 树状dp
  9. delphi使用 第三方控件
  10. Java时间转换类实现
  11. kontalk
  12. ArcGIS API for Silverlight学习笔记
  13. WM_PAINT消息小结
  14. STL之iterator(迭代器)
  15. C#工作笔记
  16. 文本宽度的测量--measureText
  17. 开发过程中,ps要做的事情
  18. .NET Core 事件总线,分布式事务解决方案:CAP 基于Kafka
  19. python-web自动化-文件上传操作(非input标签的上传,需要借助第三方工具)
  20. [转]php,使用Slim和Medoo搭建简单restful服务

热门文章

  1. uva 11468 AC自动机+概率DP
  2. Team Contests - Warmup(2016年多校热身赛,2016年黑龙江省赛)
  3. 转 Django+Bootstrap练习--我的类博客系统开发
  4. The disk contains an unclean file system
  5. Servlet 2.4 规范之第三篇:Servlet生命周期
  6. LeetCode OJ——Pascal&#39;s Triangle
  7. vs2017秘钥
  8. UVA 10635 Prince and Princess【LCS 问题转换为 LIS】
  9. Remove Nth Node From End of List(链表,带测试代码)
  10. Uoj #350. 新年的XOR