快速排序算法的两种实现
2021-01-27 07:12
                         标签:实现   ack   author   fun   class   ring   date   @param   main    
 * 快速排序
 */
public class QuickSort {
  /**
     * 快速排序
     * @param arr 目标数组
     */
  public static int[] quickSort(int[] arr) {
    // 判断基线条件
    if (arr.length  num  num > pivot).toArray();
    // 递归拼接
    return contact(quickSort(less), pivot, quickSort(greater));
  }
  /**
     * 数组 + 数据 + 数组 拼接方法
     *
     * @param arrLess       less数组
     * @param pivot         基准值
     * @param arrGreater    greater数组
     * @return              合并后的数组
     */
  public static int[] contact(int[] arrLess, int pivot, int[] arrGreater) {
    int[] resultArr = new int[arrLess.length + arrGreater.length + 1];
    System.arraycopy(arrLess, 0, resultArr, 0, arrLess.length);
    resultArr[arrLess.length] = pivot;
    System.arraycopy(arrGreater, 0, resultArr, arrLess.length + 1, arrGreater.length);
    return resultArr;
  }
  public static void main(String[] args) {
    int[] tempArr = {4, 6, 8, 1, 2, 9, 5, 3, 7, 7, 2, 29, 14};
    System.out.println(Arrays.toString(quickSort(tempArr)));
  }
}
 快速排序算法的两种实现 标签:实现   ack   author   fun   class   ring   date   @param   main    原文地址:https://www.cnblogs.com/flySavior/p/12848371.html一、Java语言实现
package test;
import java.util.Arrays;
/**
 * @author lt
 * @date 2020-05-07 17:15
 * 二、python语言实现
def quicksortfun(arr):
  if len(arr)  pivot]
    return quicksortfun(less) + [pivot] + quicksortfun(greater)