# 一题算法题

0

0

0

http://www.cnblogs.com/eaglet/archive/2009/05/01/1447481.html

eaglet | 园豆：17139 (专家六级) | 2010-05-29 18:24
0

` class Program    {        static void Main(string[] args)        {            int[] arr = { 1, 32, 43, 54, 2, 3, 5, 6, 4, 2, 7, 8, 9, 9, 0 };            QuickSort(arr, 0, arr.Length - 1);            int[] result = new int[5];            int j = 0;            for (int i = arr.Length - 5; i < arr.Length; i++)            {                result.SetValue(arr[i], j);                j++;            }        }        public static void QuickSort(int[] array, int left, int right)        {            if (right - left <= 0) return;            int pivot = array[right];            int temp;            int leftPartition = left - 1;            int rightPartition = right;            while (true)            {                while (array[++leftPartition] < pivot) { }                while (rightPartition > 0 && array[--rightPartition] > pivot) { };                if (leftPartition >= rightPartition) break;                //元素交换                temp = array[leftPartition];                array[leftPartition] = array[rightPartition];                array[rightPartition] = temp;            }            //元素交换            temp = array[leftPartition];            array[leftPartition] = array[right];            array[right] = temp;            //递归调用部分            QuickSort(array, left, leftPartition - 1);                 QuickSort(array, leftPartition + 1, right);        }}}`

您需要登录以后才能回答，未注册用户请先注册