C#快速排序代碼
private static int Partition (int[] list, int i, int j) { int Key = list [i];while (i < j) { //j to the left scan while (list [j] >= Key && i < j) j--; if(i< j) list [i++] = list [j]; //i to the right scan while (list [i] <= Key && i < j) i++; IF (i < j) list [j--] = list[i]; } list [i] = Key; return i;
} public static void QuickSort (int[] list, int low, int high) { if(low < high - 1) { int Key = Partition (list, low, high); QuickSort (list, low, Key - 1); QuickSort (list, Key + 1, high); } }</pre>
本文由用戶 b5cw 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!