820复试算法 快排找第 k 小
done
ref:
https://blog.csdn.net/fengsigaoju/article/details/50728588
note:
void quicksort(int a[],int left,int right,int k)
{
int i,j,key,low,high;
low=left;
high=right;
key=a[left];
if (left<right)
{
while(low<high)
{
//hplc ; high pass, low change
while((low<high)&&(a[high]>=key)){
high--;
a[low]=a[high];
}
//lphc: low pass, high change
while((low<high)&&(a[low]<=key)){
low++;
a[high]=a[low];
}
}
a[low]=key;
//now 左右都归位:左边都小,右边都大的
if (low==k-1)
printf("%d\n",a[low]);
else
{
if (low<k-1)
quicksort(a,low+1,right,k);
else
quicksort(a,left,low-1,k);
}
}
}
todo {20-01-29 12:56}