import java.util.Arrays;
public class Bubble {
public static void main(String[] args) {
int b[] = {8,6,7,5,3,5,2};
int c = b.length;
int t = 0;
for(int i = 1; i < c; i++){
for(int j = 0; j < c-i; j++){
if(b[j] > b[j+1]){
t = b[j];
b[j] = b[j+1];
b[j+1] = t;
}
}
}
System.out.println(Arrays.toString(b));
}
}java描述冒泡排序(个人随笔)
最新推荐文章于 2025-12-19 15:39:34 发布
本文介绍了一个简单的冒泡排序算法实现,通过双重循环比较并交换数组中的元素,最终将无序数组按升序排列。
123

被折叠的 条评论
为什么被折叠?



