Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Lab1_wariacje_bez_powtorzen
  4. {
  5. class per_bez_powt
  6. {
  7. static void Main(string[] args)
  8. {
  9. int[] array = { 1, 2, 3, 4 };
  10. Perm(array, 0);
  11. Console.ReadKey();
  12. }
  13.  
  14. static void Perm<T>(T[] arr, int k)
  15. {
  16. if (k >= arr.Length)
  17. Print(arr);
  18. else
  19. {
  20. Perm(arr, k + 1);
  21. for (int i = k + 1; i < arr.Length; i++)
  22. {
  23. Swap(ref arr[k], ref arr[i]);
  24. Perm(arr, k + 1);
  25. Swap(ref arr[k], ref arr[i]);
  26. }
  27. }
  28. }
  29.  
  30. private static void Swap<T>(ref T item1, ref T item2)
  31. {
  32. T temp = item1;
  33. item1 = item2;
  34. item2 = temp;
  35. }
  36.  
  37. private static void Print<T>(T[] arr)
  38. {
  39. Console.WriteLine("{" + string.Join(", ", arr) + "}");
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement