DataSharp/Mathematics/CombinationHelper.cs
/// <summary>
/// Add the next combination of a into the collection of combinations.
/// </summary>
/// <typeparam name="T">The type of elements in the array.</typeparam>
/// <param name="a">A array that contains all elements involved in the combination problem.</param>
/// <param name="combination">The combination computed by the caller.</param>
/// <param name="numSelection">The number of elements to be selected.</param>
/// <param name="combinations">The collection of combinations that need to be extracted.</param>
Add the next combination of a into the collection of combinations.
Add the next combination of a into the collection of combinations .
private static void AddNextCombination<T>(T[] a, int[] combination, int numSelection, LinkedList<T[]> combinations)
        {
            T[] nextCombination = new T[numSelection];
            int j = 0;
            for (int i = 0; i < a.Length; i++)
            {
                if (combination[i] == 1)
                    nextCombination[j++] = a[i];
            }
            combinations.AddLast(nextCombination);
        }
private static void AddNextCombination < T > ( T [ ] a , int [ ] combination , int numSelection , LinkedList < T [ ] > combinations ) { T [ ] nextCombination = new T [ numSelection ] ; int j = 0 ; for ( int i = 0 ; i < a . Length ; i ++ ) { if ( combination [ i ] == 1 ) nextCombination [ j ++ ] = a [ i ] ; } combinations . AddLast ( nextCombination ) ; }
Add the next combination of a into the collection of combinations.
Add the next combination of a into the collection of combinations .
// Initializes the array to store the extracted elements. // The next index that the next element to add to. // Add the selected elements if its value in the combination[] is 1. // Add the array of combination to the LinkedList.
a
T[]
A array that contains all elements involved in the combination problem.
A array that contains all elements involved in the combination problem .
combination
int[]
The combination computed by the caller.
The combination computed by the caller .
numSelection
int
The number of elements to be selected.
The number of elements to be selected .
combinations
LinkedList<T[]>
The collection of combinations that need to be extracted.
The collection of combinations that need to be extracted .
typeparam
The type of elements in the array.
The type of elements in the array .