[C#] C#快速排序代码演示 →→→→→进入此内容的聊天室

来自 , 2019-02-24, 写在 C#, 查看 154 次.
URL http://www.code666.cn/view/137bdd55
  1. private static int Partition (int[] list, int i, int j)
  2. {
  3.     int Key = list [i];
  4.  
  5.     while (i < j)
  6.     {
  7.         //j to the left scan
  8.         while (list [j] >= Key && i < j)
  9.             j--;
  10.  
  11.         if(i< j)
  12.             list [i++] = list [j];
  13.  
  14.         //i to the right scan
  15.         while (list [i] <= Key && i < j)
  16.             i++;
  17.  
  18.         IF (i < j)
  19.             list [j--] = list[i];
  20.     }
  21.  
  22.     list [i] = Key;
  23.     return i;
  24. }
  25. public static void QuickSort (int[] list, int low, int high)
  26. {
  27.     if(low < high - 1)
  28.     {
  29.         int Key = Partition (list, low, high);
  30.         QuickSort (list, low, Key - 1);
  31.         QuickSort (list, Key + 1, high);
  32.     }
  33. }
  34. //csharp/7785

回复 "C#快速排序代码演示"

这儿你可以回复上面这条便签

captcha