冒泡排序
冒泡排序
冒泡排序
理解算法的方法
#include <stdio.h>
int main() {
int a
[8] = {2,6,5,8,9,7,4,3};
for (int i
= 0; i
< 10; ++i
) {
for (int j
= 0; j
< 8 - 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
< 8; ++i
) {
printf("%d",a
[i
]);
}
return 0;
}
转载请注明原文地址: https://lol.8miu.com/read-153.html