`
fyc92
  • 浏览: 1939 次
最近访客 更多访客>>
社区版块
存档分类
最新评论

排序算法-快速排序

阅读更多
public static void quick_sort(int[] a, int begin, int end){
		int start = 0;
		if (begin < end) {
			start = a[begin];
			int low = begin;
			int high = end;
			while(low < high){
				while(low < high && a[high] > start){
					high --;
				}
				a[low] = a[high];
				while(low < high && a[low] <= start){
					low ++;
				}
				a[high] = a[low];
			}
			a[low] = start;
			TIMES ++;
			quick_sort(a, begin, low - 1);
			quick_sort(a, low + 1, end);
		}
	}

public static int TIMES = 0;

public static void main(String[] args) {
		// TODO Auto-generated method stub    
		int a[] = {21,30,2,5,8,12,44,55,63,63,65};
		
		TIMES = 0;
        quick_sort(a, 0, a.length - 1);
		for (int i = 0; i < a.length; i++) {
			System.out.print(a[i]+",");
		}
		System.out.println("Quick Sort times : "+TIMES);
	}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics