Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static List<string[]> GenerateCombinations(string[] elements, int N)
- {
- List<string[]> combinations = new List<string[]>();
- GenerateCombinationsRecursive(elements, N, 0, new string[N], combinations);
- return combinations;
- }
- static void GenerateCombinationsRecursive(string[] elements, int N, int startIndex, string[] currentCombination, List<string[]> combinations)
- {
- if (N == 0)
- {
- combinations.Add((string[])currentCombination.Clone());
- return;
- }
- for (int i = startIndex; i < elements.Length; i++)
- {
- currentCombination[currentCombination.Length - N] = elements[i];
- GenerateCombinationsRecursive(elements, N - 1, i + 1, currentCombination, combinations);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement