简洁清晰的quicksort核心代码

void quicksort(Item a[], int l, int r)
{ 
	int i = l-1, j = r; 
	Item v = a[r];
	if (r <= l) return;
	for (;;)
	{ 
		while (a[++i] < v) ;
		while (v < a[--j]) if (j == l) break;
		if (i >= j) break;
		exch(a[i], a[j]);
	} 
	exch(a[i], a[r]);
	quicksort(a, l, i-1);
	quicksort(a, i+1, r);
}

  

posted on 2013-10-09 17:34  macrosoft  阅读(191)  评论(0编辑  收藏  举报

导航