void BubbleSort(int arr[],int count)
{
int temp=0;
bool swapped=false;
for(int i=1;i<count;i++)
{
swapped=false;
for(int j=count-1;j>=i;j--)
{
if(arr[j-1]>arr[j])
{
temp=arr[j-1];
arr[j-1]=arr[j];
arr[j]=temp;
}
swapped=true;
}
if(!swapped)//本趟排序未发生交换,提前终止算法
return;
}
}
冒泡排序
最新推荐文章于 2025-05-19 09:28:05 发布