#include <stdlib.h>
#include <stdio.h>
template <typename T>
size_t Partition(T iData[], size_t i, size_t j)
{
T iCurValue = iData[i];
while (i < j)
{
if (iData[j] <= iCurValue)
{
iData[i] = iData[j];
while (i < j)
{
if (iData[++i] >= iCurValue)
{
iData[j] = iData[i];
break;
}
}
}
j--;
}
iData[i] = iCurValue;
return i;
}
template <typename T>
void QuickSort(T iData[], size_t ibegin, size_t iend)
{
size_t iPartPos = 0;
if (ibegin < iend)
{
iPartPos = Partition(iData, ibegin, iend);
QuickSort(iData, ibegin, iPartPos-1);
QuickSort(iData, iPartPos+1, iend);
}
return;
}
排序算法--快排
最新推荐文章于 2022-01-31 10:37:52 发布