Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Lab1_wariacje_bez_powtorzen
- {
- class war_bez_powt
- {
- static void Main()
- {
- int size = 4;
- int length = 2;
- char[] variations = new char[length];
- char[] initailSet = { 'a', 'b', 'c', 'd' };
- GenerateVariationsWithoutRepetitions(0, variations, initailSet, size, length);
- Console.ReadKey();
- }
- static void GenerateVariationsWithoutRepetitions(int index, char[] variations, char[] set, int size, int length)
- {
- if (index >= length)
- {
- PrintVariations(variations);
- }
- else
- {
- for (int i = index; i < size; i++)
- {
- variations[index] = set[i];
- Swap(ref set[i], ref set[index]);
- GenerateVariationsWithoutRepetitions(index + 1, variations, set, size, length);
- Swap(ref set[i], ref set[index]);
- }
- }
- }
- private static void Swap<T>(ref T v1, ref T v2)
- {
- T temp = v1;
- v1 = v2;
- v2 = temp;
- }
- static void PrintVariations(char[] arr)
- {
- Console.WriteLine("(" + string.Join(", ", arr) + ")");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement