// 對r[
{typedef struct
{ int low
node s[n+
int quickpass(rectype r[]
int top=
while (top>
{ss=s[top]
if (ss<tt)
{k=quickpass(r
if (k
if (tt
}
} // 算法結束
int quickpass(rectype r[];int s
{i=s; j=t; rp=r[i]; x=r[i]
while (i<j)
{while (i<j && x<=r[j]
if (i<j) r[i++]=r[j];
while (i<j && x>=r[j]
if (i<j) r[j
]
r[i]=rp;
return (i);
} // 一次劃分算法結束
[算法討論]可對以上算法進行兩點改進
int top=
ss=s[top]
while (flag || top>
{k=quickpass(r
if (k
{if (k
{s[++top]
if (tt
else flag=false; // 右部處理完
}
else if (tt
{s[++top]
if (k
else flag=false // 左部處理完
}
if (!flag && top>
{ss=s[top]
} // end of while (flag || top>
} // 算法結束
int quickpass(rectype r[];int s
// 用
{ int i=s
rectype tmp;
if (r[i]
if (r[mid]
{tmp=r[j];r[j]=r[mid];
if (tmp>r[i]) r[mid]=tmp; else {r[mid]=r[i];r[i]=tmp }
}
{tmp=r[i];r[i]=r[mid];r[mid]=tmp }
// 三者取中
rp=r[i]; x=r[i]
while (i<j)
{while (i<j && x<=r[j]
if (i<j) r[i++]=r[j];
while (i<j && x>=r[j]
if (i<j) r[j
]
r[i]=rp;
return (i);
} // 一次劃分算法結束
[
From:http://tw.wingwit.com/Article/program/sjjg/201311/23182.html