潇潇雨雨
private static void Permutation(List<int> v, int m, int n)
{
int i;
if (m < n - 1)
{
Permutation(v, m + 1, n);
for (i = m + 1; i < n; i++)
{
Swap(v, m, i);
Permutation(v, m + 1, n);
Swap(v, m, i);
}
}
else
{
foreach (int vs in v)
{
Console.Write(vs);
}
Console.Write("\r\n");
}
}
private static void Swap(List<int> v, int m, int i)
{
int t;
t = v[m]; v[m] = v[i]; v[i] = t;
}
调用方法:
List<int> v = new List<int> { 1, 2, 3};
Permutation(v, 0, 3);