SHARE
TWEET

Untitled

a guest Mar 20th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2.  
  3.  
  4. namespace Lab1_wariacje_bez_powtorzen
  5. {
  6.     class war_bez_powt
  7.     {
  8.         static void Main()
  9.         {
  10.             int size = 4;
  11.             int length = 2;
  12.  
  13.             char[] variations = new char[length];
  14.             char[] initailSet = { 'a', 'b', 'c', 'd' };
  15.  
  16.             GenerateVariationsWithoutRepetitions(0, variations, initailSet, size, length);
  17.             Console.ReadKey();
  18.         }
  19.  
  20.         static void GenerateVariationsWithoutRepetitions(int index, char[] variations, char[] set, int size, int length)
  21.         {
  22.             if (index >= length)
  23.             {
  24.                 PrintVariations(variations);
  25.             }
  26.             else
  27.             {
  28.                 for (int i = index; i < size; i++)
  29.                 {
  30.                     variations[index] = set[i];
  31.                     Swap(ref set[i], ref set[index]);
  32.                     GenerateVariationsWithoutRepetitions(index + 1, variations, set, size, length);
  33.                     Swap(ref set[i], ref set[index]);
  34.                 }
  35.             }
  36.         }
  37.  
  38.         private static void Swap<T>(ref T v1, ref T v2)
  39.         {
  40.             T temp = v1;
  41.             v1 = v2;
  42.             v2 = temp;
  43.         }
  44.  
  45.         static void PrintVariations(char[] arr)
  46.         {
  47.             Console.WriteLine("(" + string.Join(", ", arr) + ")");
  48.         }
  49.     }
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top