typedef int KeyType;
typedef struct {
KeyType key;
} RecordType;
typedef struct
{
RecordType * r;
int length;
}SqList;
int Partition(SqList * L, int low, int high)
{
L->r[0] = L->r[low];
KeyType povitKey = L->r[low].key;
while (low < high)
{
while (low < high && L->r[high].key >= povitKey)
{
high--;
}
L->r[low] = L->r[high];
while (low < high && L->r[low].key <= povitKey)
{
low++;
}
L->r[high] = L->r[low];
}
L->r[low] = L->r[0];
return low;
}
void Sort(SqList * L, int low, int high)
{
if(low < high)
{
int povitLocation = Partition(L, low, high);
Sort(L, low, povitLocation - 1);
Sort(L, povitLocation + 1, high);
}
}
void QSort(SqList * L)
{
Sort(L, 1, L->length);
}
Quick Sort
最新推荐文章于 2025-05-20 09:34:15 发布
9万+

被折叠的 条评论
为什么被折叠?



