Interface
#include <codecogs/maths/combinatorics/permutations/permutation3.h>
using namespace Maths::Combinatorics::Permutations;
| class | Permutation3
Progressively generates all the permutations of the given size. | [constructor] | Permutation3 (int n) constructor that initializes the class to generate permutations of size n | | std::vector<int> | getNext () generates the next permutation; if all have been considered, it starts again from the first | | bool | isEven () returns true if the current permutation is even, otherwise false | | int | getRank () returns the rank of the current permutation | | int | m_n | | std::vector<int> m_p | unknown | | bool | m_done | | void | init () |
|
Use the following HTML code to embed the calculators within other websites:
Class Permutation3
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/permutation3.h>
#include <iostream>
int main()
{
Maths::Combinatorics::Permutations::Permutation3 P(7);
std::cout << "The first 6 permutations of 7 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 first 6 permutations of 7 elements:
1 2 3 4 5 6 7 is even rank = 1
1 2 3 4 5 7 6 is odd rank = 2
1 2 3 4 7 5 6 is even rank = 3
1 2 3 7 4 5 6 is odd rank = 4
1 2 7 3 4 5 6 is even rank = 5
1 7 2 3 4 5 6 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.