您的位置:首页 > 产品设计 > UI/UE

快速排序QuickSort

2015-04-11 09:51 225 查看
void Qsort(int * numbers,int low,int high)
{
if(low<high)
{
int i=low+1,j=high;
int ran; ran = (low + high) / 2;
swap(&numbers[ran], &numbers[low]);
int key = numbers[low];
while(i<=j){
while((numbers[j]>key)&&(low<=j))
j--;
while((numbers[i]<=key)&&(i<=high))//note: either i, or j >= or <=,or will cause infinite loop when numbers have //same number.
i++;
if (i < j)
{
swap(&numbers[i],&numbers[j]);
swap(&orders[i], &orders[j]);
}
}
swap(&numbers[low], &numbers[j]);//swap j!!
Qsort(numbers,orders,low,j-1);
Qsort(numbers,orders,j+1,high);
}
}


快速排序中比较快的版本//kind of faster version
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: