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); } } }
最後更新:2017-04-02 04:26:02