手记

快速排序

import java.util.Arrays;

/**
 * 快速排序
 *
 */
public class Sort5 {
	public static void sort(int A[],int _left,int _right){
		if(_left>=_right){
			return;
		}
		int left = _left;
		int right = _right;
		int base = A[left];
		while(left<right){
			while(left<right&&A[right]>base){
				right--;
			}
				A[left] = A[right];
			while(left<right&&A[left]<=base){
				left++;
			}
				A[right] = A[left];
		}
		A[right]= base;
		base = right;
		sort(A,_left,base-1);
		sort(A,base+1,_right);
		
		System.out.println(Arrays.toString(A));
	}
}

0人推荐
随时随地看视频
慕课网APP