int partition(int a[], int p, int r)
{
int i = p;
int j = r + 1;
int x = a[p];
while(1){
while(i<r && a[++i]<x);
while(a[--j]>x);
if(i>=j) break;
swap(a,i,j);
}
swap(a,j,p);//填空
//i本来是指向比标志小的部分,j是指向大的部分,但当break的时候j指向小的数,i指向大的数,所以需要将a[j]也就是小的数与标志换位置,再将标志所对的位置j作为下次划分的划分点
return j;
}
note:数据结构,排序,循环