//--------------------quicksort.cpp-------------------------
template<typename ElementType>
void split(ElementType x[],int first,int last)
{
ElementType pivot=x[first];
int left=first,
right=last;
while(left<right)
{
while(x[right]>pivot)
right--;
while(left<right&&(x[left]<pivot||x[left]==pivot))
left++;
if(left<right)
swap(x[left],x[right]);
}
int pos=right;
x[first]=x[pos];
x[pos]=pivot;
return pos;
}
template<typename ElementType>
void quicksort(int x[],int first,int last)
{
int pos;
if(first<last)
{
pos=spilt(x,first,last);
quicksort(x,first,pos-1);
quicksort(x,pos+1,last);
}
}
快速排序模板
最新推荐文章于 2022-06-20 11:39:57 发布