admin管理员组

文章数量:1530845

2024年3月15日发(作者:)

for (int i = n; i >= m; i--)

{

b[m - 1] = i - 1;

if (m > 1)

{

GetCombination(ref list, t, i - 1, m - 1, b, M);

}

else

{

if (list == null)

{

list = new List();

}

T[] temp = new T[M];

for (int j = 0; j < ; j++)

{

temp[j] = t[b[j]];

}

(temp);

}

}

}

///

/// 递归算法求排列(私有成员)

///

/// 返回的列表

/// 所求数组

/// 起始标号

/// 结束标号

private static void GetPermutation(ref List list, T[] t, int startIndex, int endIndex)

{

if (startIndex == endIndex)

{

if (list == null)

{

list = new List();

}

T[] temp = new T[];

(temp, 0);

(temp);

}

else

{

for (int i = startIndex; i <= endIndex; i++)

{

Swap(ref t[startIndex], ref t[i]);

GetPermutation(ref list, t, startIndex + 1, endIndex);

Swap(ref t[startIndex], ref t[i]);

}

}

}

///

/// 求从起始标号到结束标号的排列,其余元素不变

///

/// 所求数组

/// 起始标号

/// 结束标号

/// 从起始标号到结束标号排列的范型

public static List GetPermutation(T[] t, int startIndex, int endIndex)

{

if (startIndex < 0 || endIndex > - 1)

{

return null;

}

List list = new List();

GetPermutation(ref list, t, startIndex, endIndex);

return list;

}

///

/// 返回数组所有元素的全排列

///

/// 所求数组

/// 全排列的范型

public static List GetPermutation(T[] t)

{

return GetPermutation(t, 0, - 1);

}

///

/// 求数组中n个元素的排列

///

/// 所求数组

/// 元素个数

/// 数组中n个元素的排列

public static List GetPermutation(T[] t, int n)

本文标签: 排列标号元素数组结束