日期:2014-05-17  浏览次数:20827 次

求一个排列的C#算法
比如我有一个数组或者LIST;里面放了许多数据;可以相同;尽量不用递归
现在我想实现一个排列 生成另一组数据;
如:List<int> lALL=new List<int>();里面有数据;1,20,300;这个是任意的个数的,这里少点方便举例
我想得到两位数的排列;方法List<int[]> PaiLie(List<int> ls,int count);这个定义我乱写的哈;会C#的都应该明白意思的.呵呵;
使用时 PaiLie(lAll,2);
得到的结果是几组数组;
1,20
1,300
20,1
20,300
300,1
300,20
就这样;请问方法怎么写;谢谢!
每个数据每一组中最多出现一次;当然有相同的数据出现个数不会超过总表个数(这个明白吧)
如LIST 有数据 20,20,1
答案就是
20,20
20,1
20,20
20,1
1,20
1,20
不明白的或者觉得分不够的,可以QQ联系我,QQ:908382818
c# 排列 组合

------解决方案--------------------
哈哈,顶起来
------解决方案--------------------
之前好像已有个
公历→农历
2013年06月11日
双子座
二〇一三年五月初四
癸巳〖蛇〗,戊午月,戊申日,辛酉时
今属:土;五行:水火土金;缺:木。
纳音五行:长流水。
------解决方案--------------------
LINQ试试可以不。
------解决方案--------------------

using System;
using System.Collections.Generic;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {

            int[] lAll = { 1, 20, 300 };
            List<int[]> paiLie = PaiLie(lAll);
            foreach (var item in paiLie)
            {
                Console.WriteLine(item[0]+","+item[1]);
            }
            Console.ReadLine();
        }
        public static List<int[]> PaiLie(int[] lAll)
        {
            List<int[]> paiLie = new List<int[]>();           
            for (int i = 0; i < lAll.Length; i++)
            {
                for (int j = 0; j < lAll.Length; j++)
                {
                  &