算法 快速排序

落花浮王杯 提交于 2020-01-25 00:28:25

快速排序
思想:
在这里插入图片描述
代码:

public class QuickSort {
	
	public static void quick(int[] a){
		if(a.length > 0){
			quickSort(a,0,a.length-1);
		}
		for(int b : a){
			System.out.print(b+"  ");
		}
	}

	private static void quickSort(int[] a, int low, int high) {
		if(low < high){
			int mindle = sort(a,low,high);
			quickSort(a,low,mindle-1);
			quickSort(a,mindle+1 ,high);
		}
		
	}

	private static int sort(int[] a, int low, int high) {
		int temp = a[low];
		while(low < high){
			while(low < high && temp <= a[high])
				high--;
			a[low] = a[high];
			while(low < high && temp >= a[low])
				low++;
			a[high] = a[low];
		}
		a[low] = temp;
		return low;
	}
	
	public static void main(String[] args) {
		int[] a = new int[]{19,3,5,7,89,54,78,96,52,15,55,6,4};
        QuickSort.quick(a);
	}

}

								***帅气的远远啊***
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!