冒泡排序

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;
	}

	
}

 

你可能感兴趣的:(算法)