// reverse.cpp -- 2011-10-03-21.54
#include "stdafx.h"
#include <iostream>
#include <algorithm>
#include <vector>
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, 3, 8, 9} ;
vector<int> vec1(arr1, arr1 + sizeof arr1 / sizeof (int)) ;
// reverse (beg, end) ;
// 操作前:[beg,end)标示输入序列.
// 操作后:输入序列中的所有元素被首尾翻转.
// 返回值:无.
// 备注: 此算法需求双向迭代器.
reverse (vec1.begin(), vec1.end()) ;
for_each(vec1.begin(), vec1.end(), Print<int> ()) ;
std ::cin.get() ;
return 0 ;
}
reverse
最新推荐文章于 2024-07-12 23:09:55 发布