private int PartitionTemp(int[] numbers, int low, int high, eOrderBy order) { int pivot = numbers[high]; int PoS = low; //place for swaping for (int i = low; i <= high - 1; i++) { if (order == eOrderBy.Asc) { if (numbers[i] <= pivot) { Swap(numbers, PoS, i); PoS++; } } else { if (numbers[i] >= pivot) { Swap(numbers, PoS, i); PoS++; } } } Swap(numbers, PoS, high); return(PoS); }
private void RunQuickSort(int[] numbers, int low, int high, eOrderBy orderBy) { if (low >= high) { //Console.WriteLine(string.Concat("stop", "low: ", low, " - high: ", high, ", ", string.Join(",", numbers))); return; } //Console.WriteLine(string.Concat("low: ", low, " - high: ", high, ", ", string.Join(",", numbers))); int partIdx = Partition(numbers, low, high, orderBy); //Console.WriteLine(string.Concat("low: ", low, " - high: ", partIdx-1, ", ", string.Join(",", numbers))); RunQuickSort(numbers, low, partIdx - 1, orderBy); //Console.WriteLine(string.Concat("low: ", partIdx-1, " - high: ", high, ", ", string.Join(",", numbers))); RunQuickSort(numbers, partIdx + 1, high, orderBy); }
public int[] Sort(int[] listToSort, eOrderBy orderBy) { return(DivideList(listToSort)); }
public int[] Sort(int[] numbers, eOrderBy orderBy) { RunQuickSort(numbers, 0, numbers.Length - 1, orderBy); return(numbers); }