c++模板函数
template <typename T>
int _quickSort(T* list, int low, int heigh)
{
if (low >= heigh) { return low; }
T temp = list[low];
while (low < heigh)
{
while ((list[heigh] >= temp) && (low < heigh))
{
--heigh;
}
if (low < heigh)
{
list[low] = list[heigh];
++low;
}
while ((list[low] <= temp) && (low < heigh))
{
++low;
}
if (low < heigh)
{
list[heigh] = list[low];
--heigh;
}
}
list[low] = temp;
return low;
}
template <typename T>
void QuickSort(T* list, int low, int heigh)
{
if (low >= heigh) { return; }
int a = _quickSort(list, low, heigh);
QuickSort(list, low, a - 1);
QuickSort(list, a + 1, heigh);
}
test
int main()
{
int sort[] = {6, 56, 1, 23, 35, 42, 14, 6, 7, 4};
QuickSort(sort, 0, (sizeof(sort) - 1) / sizeof(int));
return 0;
}