冒泡排序
时间:2019-11-17 17:54:16
收藏:0
阅读:70
package blog;
import java.util.Arrays;
public class bubble {
public static void main(String[] args) {
int[] a = new int[] {9,5,7,4,0,3};
asc(a);
System.out.println(Arrays.toString(a));
}
static void asc(int [] arr) {
int temp;
for(int i=0;i<arr.length-1;i++) {
for(int j=0;j<arr.length-1-i;j++) {
if(arr[j+1] < arr[j]) {
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
}
}

原文:https://www.cnblogs.com/wangsihui/p/11877106.html
评论(0)