template<class Type>
int Partition(vector<Type>& a, int start, int end)
{
Type pivot = a[end];
int i = start-1;
for (int j = start; j < end; ++j)
{
if (a[j] <= pivot)
{
swap(a[++i],a[j]);
}
}
swap(a[++i],a[end]);
return i;
}
template<class Type>
void QuickSort(vector<Type>& a, int start, int end)
{
if (start < end)
{
int pivot_pos =Partition(a,start,end);
QuickSort(a,start,pivot_pos-1);
QuickSort(a,pivot_pos+1,end);
}
}
快速排序实现_c++
最新推荐文章于 2023-06-21 21:55:50 发布