public static List <T[]> GetPermutation(T[] t, int startIndex, int endIndex) { if (startIndex < 0 || endIndex > t.Length - 1) { return(null); } List <T[]> result = new List <T[]>(); PermutationAndCombination <T> .GetPermutation(ref result, t, startIndex, endIndex); return(result); }
public static List <T[]> GetPermutation(T[] t, int n) { if (n > t.Length) { return(null); } List <T[]> list = new List <T[]>(); List <T[]> combination = PermutationAndCombination <T> .GetCombination(t, n); for (int i = 0; i < combination.Count; i++) { List <T[]> collection = new List <T[]>(); PermutationAndCombination <T> .GetPermutation(ref collection, combination[i], 0, n - 1); list.AddRange(collection); } return(list); }
private static void GetPermutation(ref List <T[]> list, T[] t, int startIndex, int endIndex) { if (startIndex == endIndex) { if (list == null) { list = new List <T[]>(); } T[] array = new T[t.Length]; t.CopyTo(array, 0); list.Add(array); return; } for (int i = startIndex; i <= endIndex; i++) { PermutationAndCombination <T> .Swap(ref t[startIndex], ref t[i]); PermutationAndCombination <T> .GetPermutation(ref list, t, startIndex + 1, endIndex); PermutationAndCombination <T> .Swap(ref t[startIndex], ref t[i]); } }
public static List <T[]> GetPermutation(T[] t) { return(PermutationAndCombination <T> .GetPermutation(t, 0, t.Length - 1)); }