Or login with:
template < class BidirectionalIterator, class OutputIterator > OutputIterator reverse_copy( BidirectionalIterator first, BidirectionalIterator last, OutputIterator result );Parameters:
| Parameter | Description |
|---|---|
| first | A bidirectional iterator pointing to the position of the first element in the source range within which the elements are being permuted |
| last | A bidirectional iterator pointing to the position one past the final element in the source range within which the elements are being permuted |
| result | An output iterator pointing to the position of the first element in the destination range to which elements are being copied |
[first, last), to another range beginning at result in such a way, that the elements in the new range are in reverse order.#include <vector> #include <algorithm> #include <iostream> using namespace std; int main() { vector <int> vec1, vec2(11); vector <int>::iterator Iter1, Iter2; int i; for (i = 10; i <= 20; i++) vec1.push_back(i); cout <<"The original vector vec1 data is:\n"; for (Iter1 = vec1.begin(); Iter1 != vec1.end(); Iter1++) cout <<*Iter1<<" "; cout <<endl; // reverse the elements in the vector reverse_copy(vec1.begin(), vec1.end(), vec2.begin()); cout <<"The copy vec2 data of the reversed vector vec1 is:\n"; for (Iter2 = vec2.begin(); Iter2 != vec2.end(); Iter2++) cout <<*Iter2<<" "; cout <<endl; cout <<"The original vector vec1 unmodified as:\n"; for (Iter1 = vec1.begin(); Iter1 != vec1.end(); Iter1++) cout <<*Iter1<<" "; cout <<endl; return 0; }
You must login to leave a messge