/**
*
* @author joejoe
* 冒泡排序
*/
public class BubbleSort {
public static void main(String[] args) {
int[] arr = new int[] { 3, 7 ,2 ,1, 9 ,0,1,6 };
int tmp = 0;
for (int i = 0; i < arr.length - 1; i++) {
for (int j = 0; j < arr.length - 1 - i; j++) {
if (arr[j] > arr[j + 1]) {
tmp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = tmp;
}
}
}
for (int m = 0; m < arr.length; m++) {
System.out.print(arr[m]+ ","); //输出 0,1,1,2,3,6,7,9,
}
}
}
java 冒泡排序
最新推荐文章于 2023-05-16 10:19:40 发布