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