• 快速排序(比较简练的实现)


    快速排序JAVA实现:

    public class FastSort {
    
      public static void swap(int[] array, int i, int j) {
        int tmp = array[i];
        array[i] = array[j];
        array[j] = tmp;
      }
    
      public static void sort(int[] array, int first, int end) {
        if (first >= end) {
          return;
        }
        int x = array[first];
        int i = first;
        int j = end + 1;
        while (true) {
          while (array[++i] < x && i < end)
            ;
          while (array[--j] > x)
            ;
          if (i >= j) {
            break;
          }
          swap(array, i, j);
        }
        swap(array, first, j);
        sort(array, first, j - 1);
        sort(array, j + 1, end);
      }
    
      /**
       * @param args
       */
      public static void main(String[] args) {
        // TODO Auto-generated method stub
        int[] array = { 3, 2, 7, 2, 5, 1, 9, 2, 8, 1 };
        sort(array, 0, 9);
        for (int i : array) {
          System.out.print(i + " ");
        }
      }
    }
  • 相关阅读:
    树的同构
    最大子列和
    多项式的表示和运算
    图1
    集合及运算
    树4
    树3
    树2
    期末作业验收
    个人总结
  • 原文地址:https://www.cnblogs.com/atai/p/8526575.html
Copyright © 2020-2023  润新知