标签:ber stat name -- key mes style gen 函数
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace app { class Program { static void Main(string[] args) { int[] arr = Insert(10); //待排序数组 DateTime beforDT = System.DateTime.Now; Sort(arr, 0, arr.Length - 1); //调用快速排序函数。传值(要排序数组,基准值位置,数组长度) DateTime afterDT = System.DateTime.Now; TimeSpan ts = afterDT.Subtract(beforDT); Console.WriteLine("DateTime总共花费{0}ms.", ts.TotalMilliseconds); Console.ReadKey(); } static int[] Insert(int count) { Random r1 = new Random(); int i = 0; int[] arr = new int[count]; while (i < count) { int a = r1.Next(10, 100000); arr[i] = a; i++; } return arr; } private static void Sort(int[] numbers, int left, int right) { //左边索引小于右边,则还未排序完成 if (left < right) { //取中间的元素作为比较基准,小于他的往左边移,大于他的往右边移 int middle = numbers[(left + right) / 2]; int i = left - 1; int j = right + 1; while (true) { while (numbers[++i] < middle && i < right) ; while (numbers[--j] > middle && j > 0) ; if (i >= j) break; Swap(numbers, i, j); } Sort(numbers, left, i - 1); Sort(numbers, j + 1, right); } } private static void Swap(int[] numbers, int i, int j) { int number = numbers[i]; numbers[i] = numbers[j]; numbers[j] = number; } } }
标签:ber stat name -- key mes style gen 函数
原文地址:https://www.cnblogs.com/tianranhui/p/10175566.html