冒泡排序
package array;
import java.util.Arrays;
public class maoppxu {
public static void main(String[] args) {
//比较相邻的两个位置,大小交换降序
int[] a = {55,6,13,85,26};
int[] sort=sort(a);
System.out.println(Arrays.toString(sort));
}
public static int[] sort(int[] array) {
int temp;
for (int i = 0; i < array.length - 1; i++) {
for (int j = 0; j < array.length - 1; j++) {
if (array[j + 1] < array[j]) {
temp = array[j + 1];
array[j + 1] = array[j];
array[j] = temp;
}
}
}
return array; //多次判断,要有返回值
}
}

浙公网安备 33010602011771号