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

时间:2021-09-29 04:43:47

复制代码 代码如下:


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