int BubbleSort( int *a, int n) //a是待排序的整型数组,n是待排序数组的元素个数
<a target="_blank" href="https://www.ancii.com/link/v1/T7hz10usmNBMWW4x2VFv78QStJQyRawoWBPl7gfAdueVoFEAVvHHlwHc47VEUJcG/" rel="nofollow" title="{">{</a>
int i,j,temp;
for (j=0;j<n-1;j++)
for (i=0;i<n-1-j;i++)
{
if (a[i]>a[i+1]) //数组元素大小按升序排列
{
temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;
}
}
<a target="_blank" href="https://www.ancii.com/link/v1/T7hz10usmNBMWW4x2VFv78QStJQyRawoWBPl7gfAdueVoFEAVvHHlwHc47VEUJcG/" rel="nofollow" title="}">}</a>
|