using System namespace ConsoleApplication public class Program private

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
namespace ConsoleApplication {
public class Program {
private const int n = 3;
private static int[] permut = new int[n];
private static bool[] visit = new bool[n];
public static void Main(string[] args) {
genPermuts(0);
}
private static void print() {
foreach (int number in permut) {
Console.Write(number + " ");
}
Console.WriteLine();
}
private static void genPermuts(int pos) {
if (pos == n) {
print();
return;
}
for (int i = 0; i < n; i++) {
if (!visit[i]) {
permut[pos] = i;
visit[i] = true;
genPermuts(pos + 1);
visit[i] = false;
}
}
}
}
}