// rotate.cpp -- 2011-10-03-16.26
#include "stdafx.h"
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
using std ::vector ;
template<class T>
class Print
{
public:
void operator () (const T & t) const
{
std ::cout << t << " " ;
}
} ;
int _tmain(int argc, _TCHAR* argv[])
{
int arr1[] = {1, 2, 3, 4, 5 ,6, 7, 8 ,9} ;
vector<int> vec1(arr1, arr1 + sizeof arr1 / sizeof (int)) ;
// rotate (beg, mid, end) ;
// 操作前:[beg,end)标示输入序列.mid是输入序列中的一个迭代器.
// 操作后:mid指向的元素被移动到输入序列的第一个位置.
// 紧随其后的是输入序列中范围在[mid + 1, end - 1]中的元素.
// 再后面是[beg, mid - 1]的范围中的元素.
// 返回值:无.
// 备注: 被mid分开的两段序列重新被放入输入序列时的相对位置不改变.
rotate(vec1.begin(), vec1.begin() + 3, vec1.end()) ;
for_each(vec1.begin(), vec1.end(), Print<int> ()) ;
std ::cin.get() ;
return 0 ;
}
rotate
最新推荐文章于 2021-08-03 19:51:50 发布