Results 1 to 6 of 6

Thread: The next_permutation() in the C++

  1. #1
    Join Date
    Jan 2010
    Posts
    29

    The next_permutation() in the C++

    I had learned the C++ language programming in first year of the graduation. I could know about the in-built functions that can be present in the header files of the libraries of the C++ language. I could must have to submit the assignment on the next_permutation() function. So, I want to know about the next_permutation() function of the C++ programming language. I want to know about the use of the next_permutation() function in C++ programming.

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

    The next_permutation()

    The next_permutation() function can made an attempts to transfer the available specified range of an elements as [strt,nd) into the another lexicographically maximum permutation of an elements. If the next_permutation() function can not be succeeds then the next_permutation() function can returns the false value else the next_permutation() function can returns the true value on success. If a compulsory weak sequencing function object can be provided then the next_permutation() function can be used in lieu of an operator less than "<" when comparing an elements.
    Last edited by Reegan; 08-03-2010 at 04:50 PM.

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

    next_permutation() in the C++

    Hi, The next_permutation() function can be used in the C++ language to rearrange an elements randomly in the given specified range. The next_permutation() function can be the member of the <algorithm> header files. The following can be the syntax of the next_permutation() function in the C++ language :
    Code:
    template <class BdrctnlItrtr>
      bool next_permutation (BdrctnlItrtr fst,
                             BdrctnlItrtr lst );

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

    Use of the next_permutation()

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

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

    Re: The next_permutation() in the C++

    The following can be the parameters of the mismatch() function in the C++ language :
    1. cmp : This parameters can be used in the C++ language for comparison function object that can taking the two values of the similar type than that those can be consisted in the given specified range. The next_permutation() function can returns the true value if the first argument can be considered less than that the second argument.
    2. fst, lst : These parameters can be used in the C++ language for the bidirectional iterators that can be to the final and starting positions of the given specified sequence. The range that can be used as [fst,lst).

  6. #6
    Join Date
    Apr 2008
    Posts
    1,948

    Re: The next_permutation() in the C++

    The code of lines that can be mentioned below gives you the knowledge about the next_permutation() function of the C++ language as :
    Code:
    #include <iostream>
    #include <cassert>
    #include <algorithm>
    #include <vector>
    using namespace std;
    int main()
    {
      vector<int> vctr1(3);
      for (int j = 0; j < 3; ++j) 
      vctr1[j] = j;
      next_permutation(vctr1.begin(), vctr1.end());
      cout << vctr1[0] << " ";
      cout << vctr1[1] << " ";
      cout << vctr1[2] << " ";
      return 0;
    }
    The output of the above :
    Code:
    0 2 1

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,054,286.44595 seconds with 15 queries