?
?
?
import java.util.Arrays;
public class MaoPaoPX {
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] a = {25,23,21,29,15,3,10};
int[] b = Arrays.copyOf(a, a.length);
System.out.print("冒泡法排序");
System.out.println();
for(int i = 1; i <=a.length -1 ; i++) {
for(int j = 0; j <= a.length -1 ; j++) {
if(a[i]<a[j]) {
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
for(int x : a) {
System.out.println(x);
}
System.out.print("选择排序");
System.out.println();
System.out.print(Arrays.toString(b));
System.out.println();
int index;
for(int i = 1; i < b.length; i++) {
index = 0;
for(int j = 1;j <= b.length -i ;j++) {
if(b[index] < b[j]) {
index = j;
}
}
int tmp = b[b.length - i];
b[b.length - i] = b[index];
b[index] = tmp;
}
for(int y : b) {
System.out.println(y);
}
}
}
|