#include "iostream"
void quicksort(int a[],int left,int right)
{ int low = left,high = right;
int key = a[left];
if(left < right)
{ while(left < right)
{
while(a[right] >= key && right > left)
{
--right;
}
a[left] = a[right];
while(a[left] <= key && right > left)
{
++left;
}
a[right] = a[left];
}
//std::cout << left<<right<<"\n";
a[right] = key;
}else
{
return;
}
quicksort(a,low,left-1);
quicksort(a,left+1,high);
}
int main()
{
int a[]={95,34,45,11,95,34,22,5,1,2,4,6,7,8,44};
quicksort(a,0,14);
for(int i =0 ;i<15;i++)
{
std::cout << a[i]<<".";
}
}
快速排序算法C++版
最新推荐文章于 2023-01-07 14:34:08 发布