Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
26
Task/Permutations/C-sharp/permutations-6.cs
Normal file
26
Task/Permutations/C-sharp/permutations-6.cs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
using System;
|
||||
class Permutations
|
||||
{
|
||||
static int n = 4;
|
||||
static int [] buf = new int [n];
|
||||
static int [] next = new int [n+1];
|
||||
|
||||
static void Main()
|
||||
{
|
||||
for (int i = 0; i < n; i++) next [i] = i + 1;
|
||||
next[n] = 0;
|
||||
rec(0);
|
||||
}
|
||||
|
||||
static void rec(int ind)
|
||||
{
|
||||
for (int i = n; next[i] != n; i = next[i])
|
||||
{
|
||||
buf [ind] = next[i];
|
||||
next[i]=next[next[i]];
|
||||
if (ind < n - 1) rec(ind + 1);
|
||||
else Console.WriteLine(string.Join(",", buf));
|
||||
next[i] = buf [ind];
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue