|
// 三维数组快速排序
static void QuickSort(AcGePoint3dArray &arr, int left, int right)
{
AcGePoint3d f, t;
int rtemp, ltemp;
ltemp = left;
rtemp = right;
f = arr[(left + right) / 2]; // 分界值
while (ltemp < rtemp)
{
while (arr[ltemp].z < f.z)
{
++ltemp;
}
while (arr[rtemp].z > f.z)
{
--rtemp;
}
if (ltemp <= rtemp)
{
t = arr[ltemp];
arr[ltemp] = arr[rtemp];
arr[rtemp] = t;
--rtemp;
++ltemp;
}
}
if (ltemp == rtemp)
{
ltemp++;
}
if (left < rtemp)
{
QuickSort(arr, left, ltemp - 1); // 递归调用
}
if (ltemp < right)
{
QuickSort(arr, rtemp + 1, right);
}
}
|
|