private static int Partition <T>(this T[] list, int startIndex, int endIndex, int pivotIndex, IComparer <T> comparer, QuickselectSortOrder order) { Swap(list, pivotIndex, startIndex); var pivot = list[startIndex]; var i = startIndex; var j = endIndex + 1; while (true) { do { i++; } while (i <= endIndex && comparer.CompareWithOrder(list[i], pivot, order) < 0); do { j--; } while (comparer.CompareWithOrder(list[j], pivot, order) > 0); if (i >= j) { Swap(list, startIndex, j); return(j); } Swap(list, i, j); } }
private static int IndexOfMin <T>(this T[] list, IComparer <T> comparer, QuickselectSortOrder order) { var minIndex = 0; for (var i = 0; i < list.Length; i++) { if (comparer.CompareWithOrder(list[i], list[minIndex], order) < 0) { minIndex = i; } } return(minIndex); }