public static int[] AsSortedIndices<T>(T[] values, Comparison<T> comparison) { List<(T, int)> ToSort = new List<(T, int)>(Helper.ArrayOfFunction(i => (values[i], i), values.Length)); ToSort.Sort((a, b) => comparison(a.Item1, b.Item1)); return ToSort.Select(t => t.Item2).ToArray(); }
public void CountingSort() { List <int> newList = new List <int>(ToSort); int max = ToSort.Max(); int[] counts = new int[max + 1]; for (int i = 0; i <= max; i++) { counts[i] = 0; } for (int j = 0; j < N; j++) { counts[ToSort[j]]++; } for (int j = 1; j <= max; j++) { counts[j] += counts[j - 1]; } for (int j = 0; j < newList.Count; j++) { newList[counts[ToSort[j]] - 1] = ToSort[j]; counts[ToSort[j]]--; } }