Results 1 to 6 of 6

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

  1. #1
    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!!

  2. #2
    Join Date
    Oct 2005
    Posts
    2,394

    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);
    }

  3. #3
    Join Date
    May 2008
    Posts
    2,393

    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).

  4. #4
    Join Date
    Feb 2008
    Posts
    1,856

    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

  5. #5
    Join Date
    Jan 2008
    Posts
    1,521

    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. #6
    Join Date
    Apr 2008
    Posts
    1,949

    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 ).

Similar Threads

  1. How to fix reverse arrow key function on Mac Office 2011
    By BonnieT in forum Windows Software
    Replies: 16
    Last Post: 26-11-2011, 01:42 PM
  2. Replies: 4
    Last Post: 18-04-2010, 05:15 AM
  3. c# function equivalent to gettime function in javascript
    By Omaar in forum Software Development
    Replies: 4
    Last Post: 10-03-2010, 09:44 PM
  4. How does abstract function differs from virtual function?
    By Maddox G in forum Software Development
    Replies: 5
    Last Post: 29-01-2010, 10:32 AM
  5. How to use a loop function to reverse a counter string?
    By LostIt in forum Software Development
    Replies: 3
    Last Post: 08-08-2009, 07:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •