排序算法-快速排序

public static int s(int[] array, int low, int height) {
  int flag = array[low];
  int i = low, j = height;
  while (i < j) {
   while (array[j] > flag && i < j) {
    j--;
   }
   while (array[i] < flag && i < j) {
    i++;
   }
   if (i < j) {
    int temp = array[j];
    array[j] = array[i];
    array[i] = temp;
   }
  }
  return i;
 }

 public static void sort(int[] array, int low, int height) {
  if (low < height) {
   int result = s(array, low, height);
   sort(array, low, result - 1);
   sort(array, result + 1, height);
  }
 }

posted @ 2017-11-04 10:34  我爱咖喱饭  阅读(79)  评论(0)    收藏  举报