ITeye博客

排序算法-快速排序

fyc92 · 2013-10-28 15:41 · 排序算法 · 编程语言 · Markdown


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);
	}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。