当前位置:主页 > 软件编程 > C代码 >

C经典冒泡排序法实现代码

时间:2020-10-07 14:28:24 | 栏目:C代码 | 点击:

复制代码 代码如下:

void BubleSort(int* siSortArray, int siLen)
{
         bool bSwapped = true;
         do
         {
                   bSwapped= false;
                   for(int i = 0; i < siLen - 1; i++)
                   {
                            if (siSortArray[i] > siSortArray[i+1]) 
                            {
                                     int temp = siSortArray[i];
                                     siSortArray[i]= siSortArray[i + 1];
                                     siSortArray[i+ 1] = temp;
                                     bSwapped= true;
                            }
                   }
         }while(bSwapped);                    
}

您可能感兴趣的文章:

相关文章