冒泡排序、选择排序

冒泡排序

int[] arr = {6,3,8,2,9,1};
System.out.println("排序前数组为:");
for (int num:arr){
    System.out.println(num+"");
}
for (int i = 0;i 
  

结果为:9 8 6 3 2 1

选择排序

//选择排序 main中
int[] noSortArray = {6,3,8,2,9,1};
selectSort(noSortArray);
for (int num : noSortArray){
    System.out.println(num);
}
//选择排序
public static void selectSort(int[] number){
    int size = number.length;
    int temp = 0;
    for (int i = 0 ; i 
  

结果:123689

你可能感兴趣的:(java,排序算法,算法)