文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>数字组合不重复的算法

数字组合不重复的算法

时间:2010-11-09  来源:chenping2008

具体的算法如下:(用递归的方法来解答的)

  Int32[] num = { 1, 2, 3 ,4};
            IList<Int32> lists = num.ToList<Int32>();
            IList<Int32> results = new List<Int32>();

            for (Int32 i = 0; i < num.Length; i++)
            {
                results.Clear();
                results.Add(num[i]);
                lists.Remove(num[i]);
                DoOthers(lists,results);
                lists = num.ToList<Int32>();
                Console.WriteLine();
            }
                Console.Read(); 

 

 private static void DoOthers(IList<int> lists,IList<Int32> results)
        {
            if (lists.Count == 0)
            {
                foreach (int item in results)
                {
                    Console.Write(item.ToString() + " ");
                }
                Console.WriteLine();
                return;
            }
            else
            {
                Int32[] temp = lists.ToArray<Int32>();
                for (Int32 i = 0; i < temp.Length; i++)
                {
                    results.Add(temp[i]);
                    lists.Remove(temp[i]);
                    DoOthers(lists, results);
                    lists.Add(temp[i]);
                    results.Remove(temp[i]);
                }
            }
        } 

 

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载