天天看點

C#遞歸求排列組合

如:根據123,可以寫出:123,132,213,231,312,321種排列組合順序。

using system;

using system.collections;

class program

{

static void main(string[] args)

permutate("12345", "", 0);

}

static void permutate(string str, string result, int length)

if (str.length == length)

console.writeline(result);

for (int i = 0; i < str.length; i++)

permutate(str.remove(i, 1), result + str[i], length);