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