C# 组合算法

 private static void perm(int[] list, int i, int n)
        {
            int j;

            if (i == n)
            {
                for (int m = 0; m < list.GetUpperBound(0) + 1; m++)
                {
                    Console.Write(list[m]);
                }
                Console.WriteLine(" ");

            }
            else
            {
                for (j = i; j <= n; j++)
                {
                    SWAP(ref list[i], ref list[j]);
                    perm(list, i + 1, n);
                    SWAP(ref list[i], ref list[j]);//数组一定要复原!!!!!
                }
            }
        }
        private static void SWAP(ref int a, ref int b)
        {
            int c = a;
            a = b;
            b = c;
        }

posted @ 2012-12-03 16:14  (二少)在南极  阅读(312)  评论(0编辑  收藏  举报