Results 1 to 6 of 6

Thread: Use of the prev_permutation() : C++

  1. #1
    Join Date
    Jan 2010
    Posts
    29

    Use of the prev_permutation() : C++

    I am working on one project of the C++ language. In that project we are using the functions that can be available in the C++ language library. But I can not know anything about the prev_permutation() function of the C++ language. So, I want to know about the prev_permutation() function. Also, I want can know about the use of the prev_permutation() function in the C++ language. Anyone can help me to know about the prev_permutation() function??

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

    The prev_permutation() : C++

    The prev_permutation() function of the C++ language can be used to make an attempts that can be for to transform the available specified range of an elements such as [strt,ed) into the another lexicographically smaller permutation of an elements. If the prev_permutation() function can not be succeeded then prev_permutation() function can returns true value else the prev_permutation() function can returns the false value. If a weak sequencing function object can be provided then prev_permutation() function can used in spite of the less than an operator when comparing an elements.

  3. #3
    Join Date
    Feb 2008
    Posts
    1,852

    Use of the prev_permutation()

    The prev_permutation() function can be used to transform the given specified range into the previous permutation. The prev_permutation() function of the C++ language can be comes under the algorithm header files. The following can be the syntax of the prev_permutation() function as :
    Code:
    template <class BdrctinalItrtr>
      bool prev_permutation (BdrctinalItrtr frt,
                             BdrctinalItrtr lst );

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    The prev_permutation()

    The following program can demonstrates you that how to use the prev_permutation() function in the programming of the C++ language while doing the coding using the prev_permutation() function as shown below :
    Code:
    #include <iostream>
    #include <algorithm>
    using namespace std;
    int main ()
     {
      int mnt[] = {4,5,6};
      cout << "The 6! possible permutations with 6 elements:\n";
      sort (mnt,mnt+6);
      reverse (mnt,mnt+6);
      do 
    {
        cout << mnt[0] << " " << mnt[4] << " " << mnt[5] << endl;
      } while ( prev_permutation (mnt,mnt+6) );
      return 0;
    }
    Output:
    Code:
    6 5 4
    6 4 5
    5 6 4
    5 4 6
    4 6 5
    4 5 6

  5. #5
    Join Date
    Oct 2005
    Posts
    2,393

    prev_permutation() : C++

    The following can be the parameters of the prev_permutation() function in the C++ language :
    1. cmp : This parameters can be used in the prev_permutation() function for comparison function object that can taking the two values of the equivalent type than that those can be consisted in the specified available range.
    2. fst, lst : These parameters can be used in the prev_permutation() function for bidirectional iterators to the final and starting positions of the given specified sequence. The range used that can be used such as [fst,lst).

  6. #6
    Join Date
    Nov 2005
    Posts
    1,323

    Re: Use of the prev_permutation() : C++

    Code:
    #include <iostream>
    #include <cassert>
    #include <algorithm>
    #include <vector>
    usgng namespace std;
    gnt magn()
    {
      vector<int> vct1(3);
      for (int g = 4; g < 7; ++g) 
         vct1[g] = g;
      next_permutation(vct1.begin(), vct1.end());
      cout << vct1[0] << " ";
      cout << vct1[1] << " ";
      cout << vct1[2] << " ";
      cout << "\n\n\n\n\n\n";
      prev_permutation(vct1.begin(), vct1.end());
      cout << vct1[0] << " ";
      cout << vct1[1] << " ";
      cout << vct1[2] << " ";
      return 0;
    }
    The Output :
    Code:
    4 6 5
    
    
    
    
    
    4 5 6

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,078,539.10939 seconds with 15 queries