Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



How the reverse() function can be used in C++

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 20-02-2010
Member
 
Join Date: Jan 2010
Posts: 26
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!!

Reply With Quote
  #2  
Old 20-02-2010
Member
 
Join Date: Oct 2005
Posts: 2,389
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);
}
Reply With Quote
  #3  
Old 20-02-2010
Member
 
Join Date: May 2008
Posts: 2,383
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);
The following can be the parameters of the reverse() function in the C++ language :
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
Reply With Quote
  #4  
Old 20-02-2010
Member
 
Join Date: Feb 2008
Posts: 1,845
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;
}
Output :
Code:
mvctor contains: 9 8 7 6 5 4 3 2 1
Reply With Quote
  #5  
Old 20-02-2010
Member
 
Join Date: Jan 2008
Posts: 1,515
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.
Reply With Quote
  #6  
Old 20-02-2010
Member
 
Join Date: Apr 2008
Posts: 1,948
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 ).
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


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 02:42 PM
Reverse Port Forwarding Wizard cannot function in Windows 7 Appaji Operating Systems 4 18-04-2010 06:15 AM
c# function equivalent to gettime function in javascript Omaar Software Development 4 10-03-2010 10:44 PM
How does abstract function differs from virtual function? Maddox G Software Development 5 29-01-2010 11:32 AM
How to use a loop function to reverse a counter string? LostIt Software Development 3 08-08-2009 08:54 PM


All times are GMT +5.5. The time now is 05:28 PM.