Re: haskell мітап, Львів
static class Program
{
static void PrintArray(int[] arr) { foreach (var i in arr) Console.Write(i + " "); Console.WriteLine(); }
static void Swap(ref int a, ref int b) { int t = a; a = b; b = t; }
static void HeapPermutation(int[] a, int size, int n)
{
if (size == 1) PrintArray(a);
for (int i = 0; i < size; i++)
{
HeapPermutation(a, size - 1, n);
Swap(ref a[i * (size % 2)], ref a[size - 1]);
}
}
static void Main(string[] args)
{
int[] a = { 1, 2, 3, 4, 5 };
HeapPermutation(a, a.Length, a.Length);
}
}