public static IEnumerable <T> QuickSort <T>(this IEnumerable <T> source, Config.PivotType type, Func <T, T, bool> comparer) { List <T> list = source.ToList(); QuickListSort(list, 0, list.Count - 1, type, comparer); return(list); }
private static void QuickListSort <T>(List <T> source, int begin, int end, Config.PivotType type, Func <T, T, bool> comparer) { if (begin < end) { int partition = 0; if (type == Config.PivotType.HEADER) { partition = Partition(source, begin, end, begin, comparer); } else if (type == Config.PivotType.END) { partition = Partition(source, begin, end, end, comparer); } else { partition = Partition(source, begin, end, (begin + end) / 2, comparer); } QuickListSort(source, begin, partition, type, comparer); QuickListSort(source, partition + 1, end, type, comparer); } }