c/c++语言开发共享C语言——<算法>_冒泡算法的使用及理解

对数组内数值进行有规则排序时,就要用冒泡算法,也是比较简单的一个算法 include include int main() { int a[] = { 5,26,7,22,3,36,30,12,80,15,32 }; // printf(“%d”,_countof(a)); for (int i = …


对数组内数值进行有规则排序时,就要用冒泡算法,也是比较简单的一个算法

#include <stdio.h> #include <stdlib.h> int main() {     int a[] = { 5,26,7,22,3,36,30,12,80,15,32 }; //  printf("%d",_countof(a));     for (int i = 0; i < _countof(a) -1;++i) {         for (int j =0; j < _countof(a) -i-1;++j) {             if (a[j] > a[j+1]) {                 int k = a[j];                 a[j] = a[j + 1];                 a[j + 1] = k;             }         }     }     for (int i = 0; i < _countof(a);++i) {         printf("%dn",a[i]);     }     return 0; } 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/c-cdevelopment/605433.html

(0)
上一篇 2021年5月13日
下一篇 2021年5月13日

精彩推荐