码迷,mamicode.com
首页 > 其他好文 > 详细

c 冒泡排序

时间:2014-07-01 22:39:38      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   for   io   div   

 

c 冒泡排序

# include <stdio.h>

//冒泡排序
void sort(int * a, int len)
{
    int i, j, t;

    for (i=0; i<len-1; ++i)
    {
        for (j=0; j<len-1-i; ++j)
        {
            if (a[j] > a[j+1])  // >表示升序 <表示降序
            {
                t = a[j];
                a[j] = a[j+1];
                a[j+1] = t; 
            }
        }
    }
}

int main(void)
{
    int a[6] = {10, 2, 8, -8, 11, 0};
    int i = 0;

    sort(a, 6);

    for (i=0; i<6; ++i)
    {
        printf("%d ", a[i]);
    }
    printf("\n");

    return 0;
}

  

c 冒泡排序,布布扣,bubuko.com

c 冒泡排序

标签:style   blog   color   for   io   div   

原文地址:http://www.cnblogs.com/mjorcen/p/3816582.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!