|
| ||||||||||
| Tags: algorithm, cpp, functions, header files, reverse |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| How the reverse() function can be used in C++
|
|
#2
| ||||
| ||||
| 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);
}
__________________ Grand Theft Auto 4 PC Video Game |
|
#3
| ||||
| ||||
| The reverse() function
The following can be the syntax of the reverse() function in the C++ language : Code: template <class BidrctnlItrtr> void reverse ( BidrctnlItrtr fst, BidrctnlItrtr lst); 1. fst, lst : These parameters can be used in the C++ language for bidirectional iterators to the final and starting positions of the given specified sequence that can be reversed. The range used can be [fst,lst).
__________________ The FIFA Manager 2009 PC Game |
|
#4
| ||||
| ||||
| reverse() function
I can advice you that to go through the following code of lines slowly and carefully to understand the reverse() function of the C++ function, that can help's you to get the information of the reverse() function in the C++ coding : Code: #include <iostream>
#include <algorchm>
#include <vector>
using namespace std;
int main ()
{
vector<int> mvctor;
vector<int>::cerator c;
for (int i=1; i<10; ++i) mvctor.push_back(i);
reverse(mvctor.begin(),mvctor.end());
cout << "mvctor contains:";
for (c=mvctor.begin(); c!=mvctor.end(); ++c)
cout << " " << *c;
cout << endl;
return 0;
} Code: mvctor contains: 9 8 7 6 5 4 3 2 1 |
|
#5
| ||||
| ||||
| 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. |
|
#6
| ||||
| ||||
| 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;
} 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 ). |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "How the reverse() function can be used in C++" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to fix reverse arrow key function on Mac Office 2011 | BonnieT | Windows Software | 16 | 26-11-2011 01:42 PM |
| Reverse Port Forwarding Wizard cannot function in Windows 7 | Appaji | Operating Systems | 4 | 18-04-2010 05:15 AM |
| c# function equivalent to gettime function in javascript | Omaar | Software Development | 4 | 10-03-2010 09:44 PM |
| How does abstract function differs from virtual function? | Maddox G | Software Development | 5 | 29-01-2010 10:32 AM |
| How to use a loop function to reverse a counter string? | LostIt | Software Development | 3 | 08-08-2009 07:54 PM |