Java 实现的快速排序

一、快排介绍

不懂基本原理的可以看一下百度百科-快速排序。有两种实现方式,一种是使用partition函数;另外就是普通的

二、Java 代码

//使用partition方法
	public void quickSort(int[] nums, int low, int high){
		if (nums==null || nums.length==0 || low > high) {
			return ;
		}
		int idx = partition(nums, low, high, low);
		quickSort(nums, low, idx-1);
		quickSort(nums, idx+1, high);
	}
	public int partition(int[] nums, int low, int high, int pivotIdx){
		int pivot = nums[pivotIdx];
		swap(nums, pivotIdx, high);
		int startIdx = low;
		for (int i = low; i < high; i++) {
			if (nums[i]= right) {  
            return;  
        }  
        int low = left;  
        int high = right;  
        int key = arr[low];  
        while (low < high) {  
            while (low < high && arr[high] >= key)  
                high--;
            if (low


你可能感兴趣的:(算法,Java,java,快速排序)