Or login with:
#include <algorithm> template < class BidirectionalIterator > void reverse( BidirectionalIterator first, BidirectionalIterator last );Parameters:
| Parameter | Description |
|---|---|
| first | A bidirectional iterator pointing to the position of the first element in the range within which the elements are being permuted |
| last | A bidirectional iterator pointing to the position one past the final element in the range within which the elements are being permuted |
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { vector <int> v1; vector <int>::iterator Iter1; int i; for ( i = 0 ; i <= 9 ; i++ ) v1.push_back( i ); cout <<"The original vector v1 is:\n ( " ; for ( Iter1 = v1.begin( ) ; Iter1 != v1.end( ) ; Iter1++ ) cout <<*Iter1<<" "; cout <<")."<<endl; // Reverse the elements in the vector reverse (v1.begin( ), v1.end( ) ); cout <<"The modified vector v1 with values reversed is:\n ( " ; for ( Iter1 = v1.begin( ) ; Iter1 != v1.end( ) ; Iter1++ ) cout <<*Iter1<<" "; cout <<")."<<endl; return 0; }
You must login to leave a messge