iter_swap
来源:互联网 发布:深度卷积网络进展 编辑:程序博客网 时间:2024/05/18 01:57
#include <iostream>using std::cout;using std::endl;#include <algorithm>#include <iterator>int main(){ int a[ 10 ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; std::ostream_iterator< int > output( cout, " " ); cout << "Array a contains:\n "; std::copy( a, a + 10, output ); std::iter_swap( &a[ 0 ], &a[ 1 ] ); // swap with iterators cout << "\nArray a after swapping a[0] and a[1] using iter_swap:\n "; std::copy( a, a + 10, output ); cout << endl; return 0;}/* Array a contains: 1 2 3 4 5 6 7 8 9 10Array a after swapping a[0] and a[1] using iter_swap: 2 1 3 4 5 6 7 8 9 10 */
#include <iostream>#include <list>#include <algorithm>using namespace std;/* PRINT_ELEMENTS() * - prints optional C-string optcstr followed by * - all elements of the collection coll * - separated by spaces */template <class T>inline void PRINT_ELEMENTS (const T& coll, const char* optcstr=""){ typename T::const_iterator pos; std::cout << optcstr; for (pos=coll.begin(); pos!=coll.end(); ++pos) { std::cout << *pos << ' '; } std::cout << std::endl;}int main(){ list<int> coll; // insert elements from 1 to 9 for (int i=1; i<=9; ++i) { coll.push_back(i); } PRINT_ELEMENTS(coll); // swap first and second value iter_swap (coll.begin(), ++coll.begin()); PRINT_ELEMENTS(coll); // swap first and last value iter_swap (coll.begin(), --coll.end()); PRINT_ELEMENTS(coll);}/* 1 2 3 4 5 6 7 8 92 1 3 4 5 6 7 8 99 1 3 4 5 6 7 8 2 */
- iter_swap
- iter_swap
- C++ iter_swap()
- STL 之swap, iter_swap, swap_ranges
- STL algorihtm算法iter_swap(29)
- STL 之swap, iter_swap, swap_ranges
- 变异算法之交换(swap, swap_ranages, iter_swap)
- C++标准库---advance()&distance()&iter_swap()
- C++中的iter_swap函数的应用
- C++ STL算法系列之十六:iter_swap
- 使用迭代器辅助函数advance,distance,iter_swap
- 泛型算法系列14:random_shuffle()&&iter_swap()&&swap()
- stl 学习笔记13 advance()distance() iter_swap()
- C++标准库笔记:算法--min/max/swap/iter_swap
- STL通用算法: iter_swap,reverse,reverse_copy,advance算法
- 简单的程序诠释C++ STL算法系列之十六:iter_swap
- 简单的程序诠释C++ STL算法系列之十六:iter_swap
- C++ STL一一迭代器相关辅助函数(advance()、distance()、iter_swap())
- LVS连接的持久时间
- Andriod: 去掉系统自带的Activity跳转动画 .
- mysql 表结构的复制和数据的复制
- 我的小窝
- C++文件读写总结
- iter_swap
- 你是否拥有技术管理者必备的能力及解决常见问题 之 技术来源于一线,永远不能脱离一线。
- define的使用技巧
- 字符设备与块设备的区别
- UDP通信的问题
- 一些防止java代码被反编译的方法 .
- PHP递归运用之转义数组
- linux中的mysql
- 微软面试之22 一个整数的二进制中表示中的1的个数