以楼上的冒泡排序为例,我给介绍一下选择排序,对象的好不好学主要是多练习多打代码,再难的也能学会,要相信铁棒能磨成针
public static void main(String[] args) {
int a[] = { 12, 41, 3, 423, 2, 43 };
for (int i = 0; i < a.length ; i++) {
for (int j = 0; j < a.length; j++) {
if (arr[i]>arr[j]) {
int max = a[i];
a[i] = a[j];
a[j] = max;
}
}
}
for (int i = 0; i < a.length; i++) {
System.out.print(a[i] + " ");
}
System.out.print(a[a.length-1]);
} |