/**
* 冒泡排序
*
* @author dell
*/
public class BubbleSort {
public static void main(String[] args) {
int[] arr = { 9, 5, 2, 0, 15, 22, 3333 };
// 定义临时变量
int temp = 0;
for (int i = 0; i < arr.length; i++) {
for (int j = i; j < arr.length - 1; j++) {
if (arr[j + 1] > arr[i]) {
temp = arr[i];
arr[i] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
}
}
Java冒泡排序
最新推荐文章于 2024-07-24 16:24:19 发布