数的全排

        static void Main(string[] args)
        {
            Console.WriteLine("请输入你想全排的数:");
            int i = int.Parse(Console.ReadLine());
            Program p = new Program();
            p.book = new int[i];
            p.hz = new int[i];
            p.dsf(0);
            Console.Read();
        }
        int[] book = null;
        int[] hz = null;
        private void dsf(int step)
        {
            if (step == hz.Length)
            {
                foreach (var item in hz)
                {
                    Console.Write(item + 1);
                }
                Console.WriteLine();
                return;
            }
            for (int i = 0; i < book.Length; i++)
            {
                if (book[i] == 0)
                {
                    hz[step] = i;
                    book[i] = 1;
                    dsf(step + 1);
                    book[i] = 0;
                }
            }
        }

 

posted @ 2017-06-08 14:36  夏风微凉  阅读(134)  评论(0编辑  收藏  举报