排序算法之冒泡排序

冒泡排序

#include <stdio.h>


void bubble_sort(int a[],int n)
{
    int i,j,temp;

    for(i = 0; i < n-1; i++)
        for(j = 0; j < n-1-i; j++)
            if(a[j] > a[j+1])
            {
                temp = a[j];
                a[j] = a[j+1];
                a[j+1] = temp;
            }
    return ;
}
int main(void)
{
    int i;
    int a[5] = {8,3,2,9,7};

    //进行冒泡排序
    bubble_sort(a,5);

    //输出排序后的数据
    for(i = 0; i < 5; i++)
        printf("%d ",a[i]);

    return 0;
}
原文地址:https://www.cnblogs.com/xiaoshi-com/p/6198915.html