using System; using System.Collections.Generic; public class Test { static List<int> RandomList(int size) { List<int> ret = new List<int>(size); for (int i = 0; i < size; i++) { } return ret; } static int MyPartition(List<int> list, int left, int right) { int start = left; int pivot = list[start]; left++; right--; while(true) { while(left <= right && list[left] <= pivot) left++; while(left <= right && list[right] > pivot) right--; if(left > right) { list[start] = list[left - 1]; list[left - 1] = pivot; return left; } int temp = list[left]; list[left] = list[right]; list[right] = temp; } } static void MyQuickSort(List<int> list, int left, int right) { if(list == null || list.Count <= 1) return; if(left < right) { int pivotIdx = MyPartition(list, left, right); //Console.WriteLine("MQS " + left + " " + right); //DumpList(list); MyQuickSort(list, left, pivotIdx - 1); MyQuickSort(list, pivotIdx, right); } } static void DumpList(List<int> list) { list.ForEach(delegate(int val) { Console.Write(val); Console.Write(", "); }); Console.WriteLine(); } public static void Main() { List<int> list = RandomList(100); DumpList(list); MyQuickSort(list, 0, list.Count); DumpList(list); } }
Standard input is empty
36, 20, 95, 25, 90, 36, 75, 60, 83, 35, 85, 54, 64, 76, 67, 98, 65, 86, 65, 51, 10, 83, 79, 50, 35, 95, 30, 98, 92, 33, 58, 16, 25, 0, 38, 36, 67, 6, 49, 97, 97, 7, 13, 50, 36, 8, 20, 96, 57, 4, 50, 80, 12, 6, 75, 20, 95, 95, 87, 53, 68, 68, 10, 86, 38, 78, 40, 14, 40, 58, 78, 69, 28, 60, 1, 29, 70, 73, 74, 15, 0, 35, 11, 38, 64, 90, 5, 39, 61, 60, 95, 53, 65, 90, 19, 28, 78, 53, 49, 6, 0, 0, 1, 4, 5, 6, 6, 6, 7, 8, 10, 10, 11, 12, 13, 14, 15, 16, 19, 20, 20, 20, 25, 25, 28, 28, 29, 30, 33, 35, 35, 35, 36, 36, 36, 36, 38, 38, 38, 39, 40, 40, 49, 49, 50, 50, 50, 51, 53, 53, 53, 54, 57, 58, 58, 60, 60, 60, 61, 64, 64, 65, 65, 65, 67, 67, 68, 68, 69, 70, 73, 74, 75, 75, 76, 78, 78, 78, 79, 80, 83, 83, 85, 86, 86, 87, 90, 90, 90, 92, 95, 95, 95, 95, 95, 96, 97, 97, 98, 98,