import java.util.Arrays;
public class 冒泡排序 {
public static void main(String[] args) {
// 冒泡排序();
选择排序();
}
private static void 选择排序() {
int a[]={55,22,66,99,11,44,77,33};
for (int i = 0; i < a.length-1; i++) {
for (int j = 1+i; j < a.length; j++) {
if(a[i]>a[j]){
int temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
System.out.println(Arrays.toString(a));
}
private static void 冒泡排序() {
int a[]={55,22,66,99,11,44,77,33};
for (int i = 0; i < a.length-1; i++) {
for (int j = 0; j < a.length-i-1; j++) {
if(a[j]>a[j+1]){
int temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
System.out.println(Arrays.toString(a));
}
}
|
|