C语言--冒泡排序

C语言--冒泡排序,第1张

C语言--冒泡排序

#include

int main()
{

    int a[10] = { 33, 43, 21, 20, 10, 54, 70, 39, 8, 47 };
    //获取数组元素个数
    int len = sizeof(a) / sizeof(int);
    for (int i = 0; i < len - 1; i++) {
        for (int j = 0; j < len - 1 - i; j++) {
            if (a[j] > a[j + 1]) {
                int temp = a[j];
                a[j] = a[j + 1];
                a[j + 1] = temp;
            }
        }
    }
    for (int i = 0; i < len; i++) {
        printf("%d ", a[i]);

    }
}

备注:以前写过很多遍,哈哈。。。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5099002.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-16
下一篇 2022-11-16

发表评论

登录后才能评论

评论列表(0条)

保存