I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
get GPL
COST (GBP)
this unit 1.75
sub units 0.00
+
0

Permutation2

Progressively generates all the permutations of the given size.
Controller: CodeCogs

get GPL add to cart

Interface

C++

Class Permutation2

This class progressively generates all the permutations of the given size, while also giving the possibility to return the rank and parity of the current permutation.

Example:

#include <codecogs/maths/combinatorics/permutations/permutation2.h>
#include <iostream>
int main()
{
  Maths::Combinatorics::Permutations::Permutation2 P(3);
  std::cout << "The permutations of 3 elements:";
  std::cout << std::endl;
  for (int i = 0; i < 6; i++)
  {
    std::vector<int> alpha = P.getNext();
    for (int j = 0; j < alpha.size(); j++)
      std::cout << alpha[j] << " ";
    if (P.isEven())
      std::cout << "\tis even";
    else
      std::cout << "\tis odd";
    std::cout << "\t rank = " << P.getRank();
    std::cout << std::endl;
  }
  return 0;
}

Output:

The permutations of 3 elements:
1 2 3   is even  rank = 1
1 3 2   is odd   rank = 2
3 1 2   is even  rank = 3
3 2 1   is odd   rank = 4
2 3 1   is even  rank = 5
2 1 3   is odd   rank = 6

References:

SUBSET, a C++ library of combinatorial routines, http://www.csit.fsu.edu/~burkardt/cpp_src/subset/subset.html

Authors

Lucian Bentea (August 2005)
Source Code

Source code is available when you agree to a GP Licence or buy a Commercial Licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.