[C#] 排列組合(遞迴)

  • 8626
  • 0
  • 2014-02-20

摘要:[C#] 排列組合(遞迴)

練習遞迴~


namespace 排列組合
{
    class Program
    {
        static void Main(string[] args)
        {
            permute("", "123");
        }

        static void permute(string result, string now)
        {
            if (now == "")
            {
                Console.WriteLine(result);
            }
            else
            {
                for (int i = 0; i < now.Length; i++)
                {
                    permute(result + now[i], now.Substring(0, i) + now.Substring(i + 1));
                }
            }
        }
    }
}

範例 :