public class Test3 {
public static void main(String[] args) {
int arr[] = {11, 10, 99, 88, 44, 55};
xuanZhe(arr);
printA(arr);
System.out.println("冒泡");
maoPao(arr);
printA(arr);
}
public static void maoPao(int arr[]){
for (int i = 0; i < arr.length-1; i++) {
for (int y = 0; y < arr.length - 1-i; y++) {
if (arr[y] > arr[y + 1]) {
int t = arr[y];
arr[y] = arr[y + 1];
arr[y + 1] = t;
}
}
}
}
public static void printA(int arr[]){
for (int x = 0; x < arr.length; x++) {
System.out.println(arr[x]);
}
}
public static void xuanZhe(int arr[]){
for (int i = 0; i < arr.length-1; i++) {
for (int y = i+1; y < arr.length ; y++) {
if (arr > arr[y]) {
int t = arr[y];
arr[y] = arr;
arr = t;
}
}
}
}
}
|
|