冒泡法排序算法(C语言实现)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/peng_apple/article/details/79612191
#include <stdio.h>
void bubble(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;
            }
        }
    }
}
int main(int argc, char *argv[])
{
    int a[10]={2,4,7,1,6,9,8,3,0,5};
    int i;
    bubble(a,10);
    for(i=0;i<10;i++)
        printf("%d  ",a[i]);

    printf("\n");
    return 0;
}

猜你喜欢

转载自blog.csdn.net/peng_apple/article/details/79612191