Click or drag to resize
Accord.NET (logo)

CombinatoricsPermutationsT Method

Enumerates all possible value permutations for a given array.

Namespace:  Accord.Math
Assembly:  Accord.Math (in Accord.Math.dll) Version: 3.8.0
Syntax
public static IEnumerable<T[]> Permutations<T>(
	T[] values,
	bool inPlace = false
)
Request Example View Source

Parameters

values
Type: T
The array whose permutations need to be generated
inPlace (Optional)
Type: SystemBoolean
If set to true, the different generated permutations will be stored in the same array, thus preserving memory. However, this may prevent the samples from being stored in other locations without having to clone them. If set to false, a new memory block will be allocated for each new object in the sequence.

Type Parameters

T

Return Value

Type: IEnumerableT
Examples
// Let's say we would like to generate all possible permutations
// of the elements (1, 2, 3). In order to enumerate all those
// permutations, we can use:

int[] values = { 1, 2, 3 };

foreach (int[] permutation in Combinatorics.Permutations(values))
{
    // The permutations will be generated in the following order:
    // 
    //   { 1, 2, 3 }
    //   { 1, 3, 2 };
    //   { 2, 1, 3 };
    //   { 2, 3, 1 };
    //   { 3, 1, 2 };
    //   { 3, 2, 1 };
    // 
}
See Also