冒泡排序

#include <stdio.h>
 
void bubbleSort(intarr[],intcount)
{
   inti = count, j;
   inttemp;
   while(i > 0)
   {
        for(j = 0; j < i - 1; j++)
        {
            if(arr[j] > arr[j + 1])
            {
                temp = arr[j];
                arr[j] = arr[j + 1];
                arr[j + 1] = temp;
            }
        }
        i--;
   }
}
 
void main(void)
{
   intarr[] = {5, 4, 1, 3, 6}; //测试数据
   bubbleSort(arr, 5); //冒泡排序
   inti;
   for(i = 0; i < 5; i++)
        printf("%4d", arr[i]); //打印排序结果
}
原文地址:https://www.cnblogs.com/dashi/p/4034658.html