你的位置:首页 > Java教程

[Java教程]Java版冒泡排序和选择排序


一、理解说明

1.理解和记忆

冒泡排序:依次定位数组元素,每次只和相邻的且符合条件的元素交换位置。

选择排序:依次在数组的每个位置,通过逐个对比选择出最大或最小的元素。

2.知识点说明

(1)数组是引用类型

当方法参数是基本数据类型时,形参值发生改变并不影响实参值。

当方法参数是引用类型时,实际传递的是引用类型的地址。将实参的地址传递给形参,这时它们指向的是相同的地址,那么当形参改变时,其实形参也改变了。

举个栗子:引用类型是数组,此时在方法中对形参数组进行排序,那么尽管方法没有返回值,实参数组的元素顺序也已经被改变了,因为它们指向的是相同的地址。

(2)实参和形参

public static void main(String[] args) {	String name = "彭于晏";/* 实参 */	sayHello(name);}private static void sayHello(String name /* 形参 */) {	System.out.println("Hello " + name + " !");}

二、代码

public class MainMethod {  /**   * 程序入口   * @param args   */  public static void main(String[] args) {    // 测试冒泡排序    JavaSort javaSort = new JavaSort(new Integer[]{ 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 });    javaSort.testBubbleSort();        // 测试选择排序    javaSort.setArr(new Integer[]{ 19, 18, 17, 16, 15, 14, 13, 12, 11, 10 });    javaSort.testSelectionSort();  }}/** * Java版冒泡排序和选择排序 */class JavaSort{    private Integer[] arr;  public JavaSort(Integer[] arr) {    super();    this.arr = arr;  }    public void setArr(Integer[] arr) {    this.arr = arr;  }    /**   * 测试冒泡排序   */  public void testBubbleSort(){    System.out.println("【 冒泡排序 】");    System.out.println("排序前:");    printArray(this.arr);    System.out.println("----------------------------------------------------------");    System.out.println("排序中:");    this.bubbleSort(this.arr);    System.out.println("----------------------------------------------------------");    System.out.println("排序后:");    printArray(this.arr);    System.out.println("**********************************************************");  }  /**   * 测试选择排序   */  public void testSelectionSort(){    System.out.println("【 选择排序 】");    System.out.println("排序前:");    printArray(this.arr);    System.out.println("----------------------------------------------------------");    System.out.println("排序中:");    this.selectionSort(this.arr);    System.out.println("----------------------------------------------------------");    System.out.println("排序后:");    printArray(this.arr);    System.out.println("**********************************************************");  }    /**   * 冒泡排序   * @param arr   */  public void bubbleSort(Integer[] arr) {    for (int x = 0; x < arr.length - 1; x++) {      for (int y = 0; y < arr.length - x - 1; y++) { // -x是为了减少循环的次数,-1是为了防止ArrayIndexOutOfBoundsException。        // 升序        if (arr[y] > arr[y+1]) {          swap(arr, y, y+1);        }        // 记录        System.out.println("当 x=" + x + ",y=" + y + " 时:");        printArray(arr);      }          }  }    /**   * 选择排序   * @param arr   */  public void selectionSort(Integer[] arr) {    for (int x = 0; x < arr.length; x++) {      for (int y = x + 1; y < arr.length; y++) {        // 升序        if (arr[x] > arr[y]) {          swap(arr, x, y);        }        // 记录        System.out.println("当 x=" + x + ",y=" + y + " 时:");        printArray(arr);      }    }  }      /**   * 交换位置   * @param arr   * @param indexA   * @param indexB   */  public void swap(Object[] arr, int indexA, int indexB){    Object temp = arr[indexA];    arr[indexA] = arr[indexB];    arr[indexB] = temp;  }    /**   * 打印数组   * @param arr   */  public void printArray(Object[] arr) {    for (int i = 0; i < arr.length; i++) {      System.out.println("\tarr[" + i + "] --> " + arr[i]);    }  }}

三、执行结果

【 冒泡排序 】排序前:  arr[0] --> 9  arr[1] --> 8  arr[2] --> 7  arr[3] --> 6  arr[4] --> 5  arr[5] --> 4  arr[6] --> 3  arr[7] --> 2  arr[8] --> 1  arr[9] --> 0----------------------------------------------------------排序中:当 x=0,y=0 时:  arr[0] --> 8  arr[1] --> 9  arr[2] --> 7  arr[3] --> 6  arr[4] --> 5  arr[5] --> 4  arr[6] --> 3  arr[7] --> 2  arr[8] --> 1  arr[9] --> 0当 x=0,y=1 时:  arr[0] --> 8  arr[1] --> 7  arr[2] --> 9  arr[3] --> 6  arr[4] --> 5  arr[5] --> 4  arr[6] --> 3  arr[7] --> 2  arr[8] --> 1  arr[9] --> 0当 x=0,y=2 时:  arr[0] --> 8  arr[1] --> 7  arr[2] --> 6  arr[3] --> 9  arr[4] --> 5  arr[5] --> 4  arr[6] --> 3  arr[7] --> 2  arr[8] --> 1  arr[9] --> 0当 x=0,y=3 时:  arr[0] --> 8  arr[1] --> 7  arr[2] --> 6  arr[3] --> 5  arr[4] --> 9  arr[5] --> 4  arr[6] --> 3  arr[7] --> 2  arr[8] --> 1  arr[9] --> 0当 x=0,y=4 时:  arr[0] --> 8  arr[1] --> 7  arr[2] --> 6  arr[3] --> 5  arr[4] --> 4  arr[5] --> 9  arr[6] --> 3  arr[7] --> 2  arr[8] --> 1  arr[9] --> 0当 x=0,y=5 时:  arr[0] --> 8  arr[1] --> 7  arr[2] --> 6  arr[3] --> 5  arr[4] --> 4  arr[5] --> 3  arr[6] --> 9  arr[7] --> 2  arr[8] --> 1  arr[9] --> 0当 x=0,y=6 时:  arr[0] --> 8  arr[1] --> 7  arr[2] --> 6  arr[3] --> 5  arr[4] --> 4  arr[5] --> 3  arr[6] --> 2  arr[7] --> 9  arr[8] --> 1  arr[9] --> 0当 x=0,y=7 时:  arr[0] --> 8  arr[1] --> 7  arr[2] --> 6  arr[3] --> 5  arr[4] --> 4  arr[5] --> 3  arr[6] --> 2  arr[7] --> 1  arr[8] --> 9  arr[9] --> 0当 x=0,y=8 时:  arr[0] --> 8  arr[1] --> 7  arr[2] --> 6  arr[3] --> 5  arr[4] --> 4  arr[5] --> 3  arr[6] --> 2  arr[7] --> 1  arr[8] --> 0  arr[9] --> 9当 x=1,y=0 时:  arr[0] --> 7  arr[1] --> 8  arr[2] --> 6  arr[3] --> 5  arr[4] --> 4  arr[5] --> 3  arr[6] --> 2  arr[7] --> 1  arr[8] --> 0  arr[9] --> 9当 x=1,y=1 时:  arr[0] --> 7  arr[1] --> 6  arr[2] --> 8  arr[3] --> 5  arr[4] --> 4  arr[5] --> 3  arr[6] --> 2  arr[7] --> 1  arr[8] --> 0  arr[9] --> 9当 x=1,y=2 时:  arr[0] --> 7  arr[1] --> 6  arr[2] --> 5  arr[3] --> 8  arr[4] --> 4  arr[5] --> 3  arr[6] --> 2  arr[7] --> 1  arr[8] --> 0  arr[9] --> 9当 x=1,y=3 时:  arr[0] --> 7  arr[1] --> 6  arr[2] --> 5  arr[3] --> 4  arr[4] --> 8  arr[5] --> 3  arr[6] --> 2  arr[7] --> 1  arr[8] --> 0  arr[9] --> 9当 x=1,y=4 时:  arr[0] --> 7  arr[1] --> 6  arr[2] --> 5  arr[3] --> 4  arr[4] --> 3  arr[5] --> 8  arr[6] --> 2  arr[7] --> 1  arr[8] --> 0  arr[9] --> 9当 x=1,y=5 时:  arr[0] --> 7  arr[1] --> 6  arr[2] --> 5  arr[3] --> 4  arr[4] --> 3  arr[5] --> 2  arr[6] --> 8  arr[7] --> 1  arr[8] --> 0  arr[9] --> 9当 x=1,y=6 时:  arr[0] --> 7  arr[1] --> 6  arr[2] --> 5  arr[3] --> 4  arr[4] --> 3  arr[5] --> 2  arr[6] --> 1  arr[7] --> 8  arr[8] --> 0  arr[9] --> 9当 x=1,y=7 时:  arr[0] --> 7  arr[1] --> 6  arr[2] --> 5  arr[3] --> 4  arr[4] --> 3  arr[5] --> 2  arr[6] --> 1  arr[7] --> 0  arr[8] --> 8  arr[9] --> 9当 x=2,y=0 时:  arr[0] --> 6  arr[1] --> 7  arr[2] --> 5  arr[3] --> 4  arr[4] --> 3  arr[5] --> 2  arr[6] --> 1  arr[7] --> 0  arr[8] --> 8  arr[9] --> 9当 x=2,y=1 时:  arr[0] --> 6  arr[1] --> 5  arr[2] --> 7  arr[3] --> 4  arr[4] --> 3  arr[5] --> 2  arr[6] --> 1  arr[7] --> 0  arr[8] --> 8  arr[9] --> 9当 x=2,y=2 时:  arr[0] --> 6  arr[1] --> 5  arr[2] --> 4  arr[3] --> 7  arr[4] --> 3  arr[5] --> 2  arr[6] --> 1  arr[7] --> 0  arr[8] --> 8  arr[9] --> 9当 x=2,y=3 时:  arr[0] --> 6  arr[1] --> 5  arr[2] --> 4  arr[3] --> 3  arr[4] --> 7  arr[5] --> 2  arr[6] --> 1  arr[7] --> 0  arr[8] --> 8  arr[9] --> 9当 x=2,y=4 时:  arr[0] --> 6  arr[1] --> 5  arr[2] --> 4  arr[3] --> 3  arr[4] --> 2  arr[5] --> 7  arr[6] --> 1  arr[7] --> 0  arr[8] --> 8  arr[9] --> 9当 x=2,y=5 时:  arr[0] --> 6  arr[1] --> 5  arr[2] --> 4  arr[3] --> 3  arr[4] --> 2  arr[5] --> 1  arr[6] --> 7  arr[7] --> 0  arr[8] --> 8  arr[9] --> 9当 x=2,y=6 时:  arr[0] --> 6  arr[1] --> 5  arr[2] --> 4  arr[3] --> 3  arr[4] --> 2  arr[5] --> 1  arr[6] --> 0  arr[7] --> 7  arr[8] --> 8  arr[9] --> 9当 x=3,y=0 时:  arr[0] --> 5  arr[1] --> 6  arr[2] --> 4  arr[3] --> 3  arr[4] --> 2  arr[5] --> 1  arr[6] --> 0  arr[7] --> 7  arr[8] --> 8  arr[9] --> 9当 x=3,y=1 时:  arr[0] --> 5  arr[1] --> 4  arr[2] --> 6  arr[3] --> 3  arr[4] --> 2  arr[5] --> 1  arr[6] --> 0  arr[7] --> 7  arr[8] --> 8  arr[9] --> 9当 x=3,y=2 时:  arr[0] --> 5  arr[1] --> 4  arr[2] --> 3  arr[3] --> 6  arr[4] --> 2  arr[5] --> 1  arr[6] --> 0  arr[7] --> 7  arr[8] --> 8  arr[9] --> 9当 x=3,y=3 时:  arr[0] --> 5  arr[1] --> 4  arr[2] --> 3  arr[3] --> 2  arr[4] --> 6  arr[5] --> 1  arr[6] --> 0  arr[7] --> 7  arr[8] --> 8  arr[9] --> 9当 x=3,y=4 时:  arr[0] --> 5  arr[1] --> 4  arr[2] --> 3  arr[3] --> 2  arr[4] --> 1  arr[5] --> 6  arr[6] --> 0  arr[7] --> 7  arr[8] --> 8  arr[9] --> 9当 x=3,y=5 时:  arr[0] --> 5  arr[1] --> 4  arr[2] --> 3  arr[3] --> 2  arr[4] --> 1  arr[5] --> 0  arr[6] --> 6  arr[7] --> 7  arr[8] --> 8  arr[9] --> 9当 x=4,y=0 时:  arr[0] --> 4  arr[1] --> 5  arr[2] --> 3  arr[3] --> 2  arr[4] --> 1  arr[5] --> 0  arr[6] --> 6  arr[7] --> 7  arr[8] --> 8  arr[9] --> 9当 x=4,y=1 时:  arr[0] --> 4  arr[1] --> 3  arr[2] --> 5  arr[3] --> 2  arr[4] --> 1  arr[5] --> 0  arr[6] --> 6  arr[7] --> 7  arr[8] --> 8  arr[9] --> 9当 x=4,y=2 时:  arr[0] --> 4  arr[1] --> 3  arr[2] --> 2  arr[3] --> 5  arr[4] --> 1  arr[5] --> 0  arr[6] --> 6  arr[7] --> 7  arr[8] --> 8  arr[9] --> 9当 x=4,y=3 时:  arr[0] --> 4  arr[1] --> 3  arr[2] --> 2  arr[3] --> 1  arr[4] --> 5  arr[5] --> 0  arr[6] --> 6  arr[7] --> 7  arr[8] --> 8  arr[9] --> 9当 x=4,y=4 时:  arr[0] --> 4  arr[1] --> 3  arr[2] --> 2  arr[3] --> 1  arr[4] --> 0  arr[5] --> 5  arr[6] --> 6  arr[7] --> 7  arr[8] --> 8  arr[9] --> 9当 x=5,y=0 时:  arr[0] --> 3  arr[1] --> 4  arr[2] --> 2  arr[3] --> 1  arr[4] --> 0  arr[5] --> 5  arr[6] --> 6  arr[7] --> 7  arr[8] --> 8  arr[9] --> 9当 x=5,y=1 时:  arr[0] --> 3  arr[1] --> 2  arr[2] --> 4  arr[3] --> 1  arr[4] --> 0  arr[5] --> 5  arr[6] --> 6  arr[7] --> 7  arr[8] --> 8  arr[9] --> 9当 x=5,y=2 时:  arr[0] --> 3  arr[1] --> 2  arr[2] --> 1  arr[3] --> 4  arr[4] --> 0  arr[5] --> 5  arr[6] --> 6  arr[7] --> 7  arr[8] --> 8  arr[9] --> 9当 x=5,y=3 时:  arr[0] --> 3  arr[1] --> 2  arr[2] --> 1  arr[3] --> 0  arr[4] --> 4  arr[5] --> 5  arr[6] --> 6  arr[7] --> 7  arr[8] --> 8  arr[9] --> 9当 x=6,y=0 时:  arr[0] --> 2  arr[1] --> 3  arr[2] --> 1  arr[3] --> 0  arr[4] --> 4  arr[5] --> 5  arr[6] --> 6  arr[7] --> 7  arr[8] --> 8  arr[9] --> 9当 x=6,y=1 时:  arr[0] --> 2  arr[1] --> 1  arr[2] --> 3  arr[3] --> 0  arr[4] --> 4  arr[5] --> 5  arr[6] --> 6  arr[7] --> 7  arr[8] --> 8  arr[9] --> 9当 x=6,y=2 时:  arr[0] --> 2  arr[1] --> 1  arr[2] --> 0  arr[3] --> 3  arr[4] --> 4  arr[5] --> 5  arr[6] --> 6  arr[7] --> 7  arr[8] --> 8  arr[9] --> 9当 x=7,y=0 时:  arr[0] --> 1  arr[1] --> 2  arr[2] --> 0  arr[3] --> 3  arr[4] --> 4  arr[5] --> 5  arr[6] --> 6  arr[7] --> 7  arr[8] --> 8  arr[9] --> 9当 x=7,y=1 时:  arr[0] --> 1  arr[1] --> 0  arr[2] --> 2  arr[3] --> 3  arr[4] --> 4  arr[5] --> 5  arr[6] --> 6  arr[7] --> 7  arr[8] --> 8  arr[9] --> 9当 x=8,y=0 时:  arr[0] --> 0  arr[1] --> 1  arr[2] --> 2  arr[3] --> 3  arr[4] --> 4  arr[5] --> 5  arr[6] --> 6  arr[7] --> 7  arr[8] --> 8  arr[9] --> 9----------------------------------------------------------排序后:  arr[0] --> 0  arr[1] --> 1  arr[2] --> 2  arr[3] --> 3  arr[4] --> 4  arr[5] --> 5  arr[6] --> 6  arr[7] --> 7  arr[8] --> 8  arr[9] --> 9**********************************************************

冒泡排序执行结果
【 选择排序 】排序前:  arr[0] --> 19  arr[1] --> 18  arr[2] --> 17  arr[3] --> 16  arr[4] --> 15  arr[5] --> 14  arr[6] --> 13  arr[7] --> 12  arr[8] --> 11  arr[9] --> 10----------------------------------------------------------排序中:当 x=0,y=1 时:  arr[0] --> 18  arr[1] --> 19  arr[2] --> 17  arr[3] --> 16  arr[4] --> 15  arr[5] --> 14  arr[6] --> 13  arr[7] --> 12  arr[8] --> 11  arr[9] --> 10当 x=0,y=2 时:  arr[0] --> 17  arr[1] --> 19  arr[2] --> 18  arr[3] --> 16  arr[4] --> 15  arr[5] --> 14  arr[6] --> 13  arr[7] --> 12  arr[8] --> 11  arr[9] --> 10当 x=0,y=3 时:  arr[0] --> 16  arr[1] --> 19  arr[2] --> 18  arr[3] --> 17  arr[4] --> 15  arr[5] --> 14  arr[6] --> 13  arr[7] --> 12  arr[8] --> 11  arr[9] --> 10当 x=0,y=4 时:  arr[0] --> 15  arr[1] --> 19  arr[2] --> 18  arr[3] --> 17  arr[4] --> 16  arr[5] --> 14  arr[6] --> 13  arr[7] --> 12  arr[8] --> 11  arr[9] --> 10当 x=0,y=5 时:  arr[0] --> 14  arr[1] --> 19  arr[2] --> 18  arr[3] --> 17  arr[4] --> 16  arr[5] --> 15  arr[6] --> 13  arr[7] --> 12  arr[8] --> 11  arr[9] --> 10当 x=0,y=6 时:  arr[0] --> 13  arr[1] --> 19  arr[2] --> 18  arr[3] --> 17  arr[4] --> 16  arr[5] --> 15  arr[6] --> 14  arr[7] --> 12  arr[8] --> 11  arr[9] --> 10当 x=0,y=7 时:  arr[0] --> 12  arr[1] --> 19  arr[2] --> 18  arr[3] --> 17  arr[4] --> 16  arr[5] --> 15  arr[6] --> 14  arr[7] --> 13  arr[8] --> 11  arr[9] --> 10当 x=0,y=8 时:  arr[0] --> 11  arr[1] --> 19  arr[2] --> 18  arr[3] --> 17  arr[4] --> 16  arr[5] --> 15  arr[6] --> 14  arr[7] --> 13  arr[8] --> 12  arr[9] --> 10当 x=0,y=9 时:  arr[0] --> 10  arr[1] --> 19  arr[2] --> 18  arr[3] --> 17  arr[4] --> 16  arr[5] --> 15  arr[6] --> 14  arr[7] --> 13  arr[8] --> 12  arr[9] --> 11当 x=1,y=2 时:  arr[0] --> 10  arr[1] --> 18  arr[2] --> 19  arr[3] --> 17  arr[4] --> 16  arr[5] --> 15  arr[6] --> 14  arr[7] --> 13  arr[8] --> 12  arr[9] --> 11当 x=1,y=3 时:  arr[0] --> 10  arr[1] --> 17  arr[2] --> 19  arr[3] --> 18  arr[4] --> 16  arr[5] --> 15  arr[6] --> 14  arr[7] --> 13  arr[8] --> 12  arr[9] --> 11当 x=1,y=4 时:  arr[0] --> 10  arr[1] --> 16  arr[2] --> 19  arr[3] --> 18  arr[4] --> 17  arr[5] --> 15  arr[6] --> 14  arr[7] --> 13  arr[8] --> 12  arr[9] --> 11当 x=1,y=5 时:  arr[0] --> 10  arr[1] --> 15  arr[2] --> 19  arr[3] --> 18  arr[4] --> 17  arr[5] --> 16  arr[6] --> 14  arr[7] --> 13  arr[8] --> 12  arr[9] --> 11当 x=1,y=6 时:  arr[0] --> 10  arr[1] --> 14  arr[2] --> 19  arr[3] --> 18  arr[4] --> 17  arr[5] --> 16  arr[6] --> 15  arr[7] --> 13  arr[8] --> 12  arr[9] --> 11当 x=1,y=7 时:  arr[0] --> 10  arr[1] --> 13  arr[2] --> 19  arr[3] --> 18  arr[4] --> 17  arr[5] --> 16  arr[6] --> 15  arr[7] --> 14  arr[8] --> 12  arr[9] --> 11当 x=1,y=8 时:  arr[0] --> 10  arr[1] --> 12  arr[2] --> 19  arr[3] --> 18  arr[4] --> 17  arr[5] --> 16  arr[6] --> 15  arr[7] --> 14  arr[8] --> 13  arr[9] --> 11当 x=1,y=9 时:  arr[0] --> 10  arr[1] --> 11  arr[2] --> 19  arr[3] --> 18  arr[4] --> 17  arr[5] --> 16  arr[6] --> 15  arr[7] --> 14  arr[8] --> 13  arr[9] --> 12当 x=2,y=3 时:  arr[0] --> 10  arr[1] --> 11  arr[2] --> 18  arr[3] --> 19  arr[4] --> 17  arr[5] --> 16  arr[6] --> 15  arr[7] --> 14  arr[8] --> 13  arr[9] --> 12当 x=2,y=4 时:  arr[0] --> 10  arr[1] --> 11  arr[2] --> 17  arr[3] --> 19  arr[4] --> 18  arr[5] --> 16  arr[6] --> 15  arr[7] --> 14  arr[8] --> 13  arr[9] --> 12当 x=2,y=5 时:  arr[0] --> 10  arr[1] --> 11  arr[2] --> 16  arr[3] --> 19  arr[4] --> 18  arr[5] --> 17  arr[6] --> 15  arr[7] --> 14  arr[8] --> 13  arr[9] --> 12当 x=2,y=6 时:  arr[0] --> 10  arr[1] --> 11  arr[2] --> 15  arr[3] --> 19  arr[4] --> 18  arr[5] --> 17  arr[6] --> 16  arr[7] --> 14  arr[8] --> 13  arr[9] --> 12当 x=2,y=7 时:  arr[0] --> 10  arr[1] --> 11  arr[2] --> 14  arr[3] --> 19  arr[4] --> 18  arr[5] --> 17  arr[6] --> 16  arr[7] --> 15  arr[8] --> 13  arr[9] --> 12当 x=2,y=8 时:  arr[0] --> 10  arr[1] --> 11  arr[2] --> 13  arr[3] --> 19  arr[4] --> 18  arr[5] --> 17  arr[6] --> 16  arr[7] --> 15  arr[8] --> 14  arr[9] --> 12当 x=2,y=9 时:  arr[0] --> 10  arr[1] --> 11  arr[2] --> 12  arr[3] --> 19  arr[4] --> 18  arr[5] --> 17  arr[6] --> 16  arr[7] --> 15  arr[8] --> 14  arr[9] --> 13当 x=3,y=4 时:  arr[0] --> 10  arr[1] --> 11  arr[2] --> 12  arr[3] --> 18  arr[4] --> 19  arr[5] --> 17  arr[6] --> 16  arr[7] --> 15  arr[8] --> 14  arr[9] --> 13当 x=3,y=5 时:  arr[0] --> 10  arr[1] --> 11  arr[2] --> 12  arr[3] --> 17  arr[4] --> 19  arr[5] --> 18  arr[6] --> 16  arr[7] --> 15  arr[8] --> 14  arr[9] --> 13当 x=3,y=6 时:  arr[0] --> 10  arr[1] --> 11  arr[2] --> 12  arr[3] --> 16  arr[4] --> 19  arr[5] --> 18  arr[6] --> 17  arr[7] --> 15  arr[8] --> 14  arr[9] --> 13当 x=3,y=7 时:  arr[0] --> 10  arr[1] --> 11  arr[2] --> 12  arr[3] --> 15  arr[4] --> 19  arr[5] --> 18  arr[6] --> 17  arr[7] --> 16  arr[8] --> 14  arr[9] --> 13当 x=3,y=8 时:  arr[0] --> 10  arr[1] --> 11  arr[2] --> 12  arr[3] --> 14  arr[4] --> 19  arr[5] --> 18  arr[6] --> 17  arr[7] --> 16  arr[8] --> 15  arr[9] --> 13当 x=3,y=9 时:  arr[0] --> 10  arr[1] --> 11  arr[2] --> 12  arr[3] --> 13  arr[4] --> 19  arr[5] --> 18  arr[6] --> 17  arr[7] --> 16  arr[8] --> 15  arr[9] --> 14当 x=4,y=5 时:  arr[0] --> 10  arr[1] --> 11  arr[2] --> 12  arr[3] --> 13  arr[4] --> 18  arr[5] --> 19  arr[6] --> 17  arr[7] --> 16  arr[8] --> 15  arr[9] --> 14当 x=4,y=6 时:  arr[0] --> 10  arr[1] --> 11  arr[2] --> 12  arr[3] --> 13  arr[4] --> 17  arr[5] --> 19  arr[6] --> 18  arr[7] --> 16  arr[8] --> 15  arr[9] --> 14当 x=4,y=7 时:  arr[0] --> 10  arr[1] --> 11  arr[2] --> 12  arr[3] --> 13  arr[4] --> 16  arr[5] --> 19  arr[6] --> 18  arr[7] --> 17  arr[8] --> 15  arr[9] --> 14当 x=4,y=8 时:  arr[0] --> 10  arr[1] --> 11  arr[2] --> 12  arr[3] --> 13  arr[4] --> 15  arr[5] --> 19  arr[6] --> 18  arr[7] --> 17  arr[8] --> 16  arr[9] --> 14当 x=4,y=9 时:  arr[0] --> 10  arr[1] --> 11  arr[2] --> 12  arr[3] --> 13  arr[4] --> 14  arr[5] --> 19  arr[6] --> 18  arr[7] --> 17  arr[8] --> 16  arr[9] --> 15当 x=5,y=6 时:  arr[0] --> 10  arr[1] --> 11  arr[2] --> 12  arr[3] --> 13  arr[4] --> 14  arr[5] --> 18  arr[6] --> 19  arr[7] --> 17  arr[8] --> 16  arr[9] --> 15当 x=5,y=7 时:  arr[0] --> 10  arr[1] --> 11  arr[2] --> 12  arr[3] --> 13  arr[4] --> 14  arr[5] --> 17  arr[6] --> 19  arr[7] --> 18  arr[8] --> 16  arr[9] --> 15当 x=5,y=8 时:  arr[0] --> 10  arr[1] --> 11  arr[2] --> 12  arr[3] --> 13  arr[4] --> 14  arr[5] --> 16  arr[6] --> 19  arr[7] --> 18  arr[8] --> 17  arr[9] --> 15当 x=5,y=9 时:  arr[0] --> 10  arr[1] --> 11  arr[2] --> 12  arr[3] --> 13  arr[4] --> 14  arr[5] --> 15  arr[6] --> 19  arr[7] --> 18  arr[8] --> 17  arr[9] --> 16当 x=6,y=7 时:  arr[0] --> 10  arr[1] --> 11  arr[2] --> 12  arr[3] --> 13  arr[4] --> 14  arr[5] --> 15  arr[6] --> 18  arr[7] --> 19  arr[8] --> 17  arr[9] --> 16当 x=6,y=8 时:  arr[0] --> 10  arr[1] --> 11  arr[2] --> 12  arr[3] --> 13  arr[4] --> 14  arr[5] --> 15  arr[6] --> 17  arr[7] --> 19  arr[8] --> 18  arr[9] --> 16当 x=6,y=9 时:  arr[0] --> 10  arr[1] --> 11  arr[2] --> 12  arr[3] --> 13  arr[4] --> 14  arr[5] --> 15  arr[6] --> 16  arr[7] --> 19  arr[8] --> 18  arr[9] --> 17当 x=7,y=8 时:  arr[0] --> 10  arr[1] --> 11  arr[2] --> 12  arr[3] --> 13  arr[4] --> 14  arr[5] --> 15  arr[6] --> 16  arr[7] --> 18  arr[8] --> 19  arr[9] --> 17当 x=7,y=9 时:  arr[0] --> 10  arr[1] --> 11  arr[2] --> 12  arr[3] --> 13  arr[4] --> 14  arr[5] --> 15  arr[6] --> 16  arr[7] --> 17  arr[8] --> 19  arr[9] --> 18当 x=8,y=9 时:  arr[0] --> 10  arr[1] --> 11  arr[2] --> 12  arr[3] --> 13  arr[4] --> 14  arr[5] --> 15  arr[6] --> 16  arr[7] --> 17  arr[8] --> 18  arr[9] --> 19----------------------------------------------------------排序后:  arr[0] --> 10  arr[1] --> 11  arr[2] --> 12  arr[3] --> 13  arr[4] --> 14  arr[5] --> 15  arr[6] --> 16  arr[7] --> 17  arr[8] --> 18  arr[9] --> 19**********************************************************

选择排序执行结果