using System.Collections.Generic;
class FullArray
{
private int Index = 0;
private Dictionary<int ,string> dic;
public FullArray()
{
dic = new Dictionary<int, string> ();
}
/// <summary>
/// 数组全排列
/// </summary>
/// <param name="listdata">Listdata.</param>
/// <param name="s">起始索引.</param>
/// <param name="e">结束索引.</param>
public Dictionary<int ,string> permlist(int[] listdata, int s, int e)
{
if (s == e) {
string str = "";
for (int i = 0; i <= e; i++)
str += listdata [i].ToString () + ",";
//System.Console.WriteLine (Index + " | " + str.TrimEnd (',')); //输出测试
dic.Add (Index, str.TrimEnd (',')); //存入字典
Index += 1; //索引递增
} else {
for (int i = s; i <= e; i++) {
Swap (ref listdata [s], ref listdata [i]);
permlist (listdata, s + 1, e);
Swap (ref listdata [s], ref listdata [i]);
}
}
return dic;
}
public void Swap(ref int a,ref int b)
{
int temp = a;
a = b;
b = temp;
}
}
using System.Linq;
int n = 3;
int[] arr = Enumerable.Range (0, n + 1).ToArray ();
IEnumerable<IEnumerable<int>> query = arr.Select (x => new int[] { x });
while (query.First().Count() != arr.GetLength(0))
query = query.SelectMany (x => arr.Where (y => !x.Contains (y)).Select (y => x.Concat (new int[] { y })));
foreach (var item in query)
Console.WriteLine (string.Join (",", item.Select (x => x.ToString ()).ToArray ()));
/// <summary>
/// 获取全排列数组
/// </summary>
public List<int[]> GetFullarray(int N)
{
int[] arr = GetIntArr (N);
IEnumerable<IEnumerable<int>> query = arr.Select (x => new int[] { x });
while (query.First ().Count () != arr.GetLength (0))
query = query.SelectMany (x => arr.Where (y => !x.Contains (y)).Select (y => x.Concat (new int[] { y })));
List<int[]> Reg = new List<int[]> ();
foreach (var item in query)
Reg.Add (item.Select (x => x).ToArray ());
return Reg;
}