std::reverse
来自cppreference.com
                    
                                        
                    
                    
                                                            
                    | 
   | 
  该页由英文版wiki使用Google Translate机器翻译而来。 
 该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里.  | 
|   在头文件 <algorithm> 中定义
   | 
||
|   template< class BidirIt > void reverse( BidirIt first, BidirIt last );  | 
||
的范围内
[first, last)中的元素的顺序反转.原文:
Reverses the order of the elements in the range 
[first, last).目录 | 
[编辑] 参数
| first, last | - |    扭转的元素范围 
 | 
| 类型要求 | ||
 -BidirIt 必须满足 BidirectionalIterator 的要求。
 | ||
 -The type of dereferenced BidirIt must meet the requirements of Swappable.
 | ||
[编辑] 返回值
(无)
[编辑] 可能的实现
template<class BidirIt> void reverse(BidirIt first, BidirIt last) { while ((first != last) && (first != --last)) { std::swap(*first++, *last); } }  | 
[编辑] 示例
#include <vector> #include <iostream> #include <algorithm> int main(int argc, char** argv) { std::vector<int> v({1,2,3}); std::reverse(std::begin(v), std::end(v)); std::cout << v[0] << v[1] << v[2] << '\n'; int a[] = {4, 5, 6, 7}; std::reverse(&a[0], &a[4]); std::cout << a[0] << a[1] << a[2] << a[3] << '\n'; }
输出:
321 7654
[编辑] 复杂度
线性
first和last之间的距离原文:
linear in the distance between 
first and last[编辑] 另请参阅
|    将区间内的元素颠倒顺序并复制   (函数模板)  |