How the reverse() function can be used in C++
Hello, I am the student of the BSC. I can have to make a Project on the functions of the C++ programming language that can be in-built into the C++ library in three days. I can also have the better knowledge of the functions that can be used in the C++ language library. But, I can not know much more about the reverse() function of the C++ language. So, I would like to know about the reverse() function of the C++ language. I also would like to know How the reverse() function can be used in C++ programming. Reply Me!!
The reverse() function can be used in C++
Hello, According to me the reverse() function can be used in the C++ language to reversed the order of an elements that can be in the given specified range [fst,lst). The behavior of the reverse() function template can be similar to the following as :
Code:
template <class BidrctnlItrtr>
void reverse ( BidrctnlItrtr fst, BidrctnlItrtr lst)
{
while ((fst!=lst)&&(fst!=--lst))
swap (*fst++,*lst);
}
The reverse() function in C++
The reverse() function of the C++ language can be used to reverse an elements in a given specified sequence so that the last element can becomes the new first element and the element that can be first becomes the new last element. The reverse() function can applies the iter_swap() function to all the pairs of the iterators start + I; (finish - I) - 1, that For each integer i <= (finish - start)/2 that can not be negative.
Re: How the reverse() function can be used in C++
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 ).