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

Reply
 
Thread Tools Search this Thread
  #1  
Old 08-03-2010
Member
 
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.
Reply With Quote
  #2  
Old 08-03-2010
Member
 
Join Date: Oct 2005
Posts: 2,389
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.
Reply With Quote
  #3  
Old 08-03-2010
Member
 
Join Date: May 2008
Posts: 2,383
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 );
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #4  
Old 08-03-2010
Member
 
Join Date: Feb 2008
Posts: 1,848
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
Reply With Quote
  #5  
Old 08-03-2010
Member
 
Join Date: Jan 2008
Posts: 1,515
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).
Reply With Quote
  #6  
Old 08-03-2010
Member
 
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
Reply With Quote
Reply

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



Thread Tools Search this Thread
Search this Thread:

Advanced Search



All times are GMT +5.5. The time now is 06:56 PM.