There can be one more program on the reverse() function in the C++ language as follows :
Code:
#include <vector>
#include <algorithm>
#include <iostream>
int main( )
{
using namespace std;
vector <int> w1;
vector <int>::iterator Itr1;
int i;
for ( i = 0 ; i <= 9 ; i++ )
{
w1.pushback( i );
}
cout << "The original vector w1 is:\n ( " ;
for ( Itr1 = w1.begin( ) ; Itr1 != w1.end( ) ; Itr1++ )
cout << *Itr1 << " ";
cout << ")." << endl;
reverse (w1.begin( ), w1.end( ) );
cout << "The modified vector w1 with values reversed is:\n ( " ;
for ( Itr1 = w1.begin( ) ; Itr1 != w1.end( ) ; Itr1++ )
cout << *Itr1 << " ";
cout << ")." << endl;
}
Output
Code:
The original vector w1 is:
( 0 1 2 3 4 5 6 7 8 9 ).
The modified vector w1 with values reversed is:
( 9 8 7 6 5 4 3 2 1 0 ).
Bookmarks