冒泡排序法

来源:互联网 发布:王小二果园淘宝店铺 编辑:程序博客网 时间:2024/06/10 05:15
package test;


public class bubbleSort {

public static void main(String[] args) {

int[] numbers = {2,9,0,7,58,62};
bubble(numbers);
}

public static void bubble(int[] numbers){
int temp;
for (int i = 0; i < numbers.length-1; i++) {
for (int j = i+1; j < numbers.length; j++) {
if (numbers[i]<numbers[j]) {
temp = numbers[i];
numbers[i] = numbers[j];
numbers[j]=temp;
}
}

}
for (int i = 0; i < numbers.length; i++) {
System.out.println(numbers[i]);
}
}
}
0 0
原创粉丝点击