DataSharp/Mathematics/CombinationHelper.cs
/// <summary>
/// Generate all the combinations with the specified number of total elements and the number of elements to be
/// extracted.
/// </summary>
/// <typeparam name="T">The type of elements in the array.</typeparam>
/// <param name="a">The array that contains all the candidate elements.</param>
/// <param name="numSelection">The number of elements to be extracted.</param>
/// <returns>
/// All the combinations with the specified number of total elements and the number of elements to be extracted.
/// </returns>
Generate all the combinations with the specified number of total elements and the number of elements to be
extracted.
Generate all the combinations with the specified number of total elements and the number of elements to be extracted .
public static IEnumerable<T[]> Combinations<T>(T[] a, int numSelection)
        {
            LengthCheck(a.Length, numSelection);
            LinkedList<T[]> combinations = new LinkedList<T[]>();
            Combinations(a, numSelection, combinations);
            return combinations;
        }
public static IEnumerable < T [ ] > Combinations < T > ( T [ ] a , int numSelection ) { LengthCheck ( a . Length , numSelection ) ; LinkedList < T [ ] > combinations = new LinkedList < T [ ] > ( ) ; Combinations ( a , numSelection , combinations ) ; return combinations ; }
Generate all the combinations with the specified number of total elements and the number of elements to be
extracted.
Generate all the combinations with the specified number of total elements and the number of elements to be extracted .
// Check length before processing. // Initialize an empty linked list to store all the combinations. // Compute all the possible combinations and store them in the linked list we initialized before. // Return all the combinations we computed above.
All the combinations with the specified number of total elements and the number of elements to be extracted.
All the combinations with the specified number of total elements and the number of elements to be extracted .
a
T[]
The array that contains all the candidate elements.
The array that contains all the candidate elements .
numSelection
int
The number of elements to be extracted.
The number of elements to be extracted .
typeparam
The type of elements in the array.
The type of elements in the array .