冒泡排序
什么是冒泡排序
冒泡排序(Bubble Sort),是计算机科学领域简单的排序算法
重复的访问每一个元素,依次相邻的两个元素进行比较大小,进行交换位置,
为什么叫冒泡排序:
- 越小的元素会经过交换位置来浮到数组的顶端,(升序或降序的排序),类似水中气泡慢慢浮现到水面
 
升序
@Test
public void testBubbling() {
    int[] a = {1, 47, 4, 36, 8, 2, 90, 2, 3};
    //将数组长度赋值给变量,(在for循环中每次计算数组长度)
    int aLength = a.length;
    System.out.println("未排序前的数组"+Arrays.toString(a));
    //排序次数
    for (int i = 1; i < aLength; i++) {
        //循环索引
        for (int j = 0; j < aLength - i; j++) {
            //比较大小
            if (a[j] > a[j + 1]) {
                //调换位置
                int stemp = a[j]; //大值赋值给变量
                a[j] = a[j + 1];//小值往前赋值
                a[j + 1] = stemp;//变量值向当前索引赋值
            }
        }
    }
    System.out.println("排序后的结果"+Arrays.toString(a));
}
 
运行结果

分析
- 依次对相邻两个元素做比较

 
降序
@Test
public void testBubbling() {
    int[] a = {1, 47, 4, 36, 8, 2, 90, 2, 3};
    //将数组长度赋值给变量,(在for循环中每次计算数组长度)
    int aLength = a.length;
    System.out.println("未排序前的数组"+Arrays.toString(a));
    //排序次数
    for (int i = 1; i < aLength; i++) {
        //循环索引
        for (int j = 0; j < aLength - i; j++) {
            //比较大小
            if (a[j] < a[j + 1]) {
                //调换位置
                int stemp = a[j+1]; //大值赋值给变量
                a[j+1] = a[j];//小值往后赋值
                a[j] = stemp;//变量值向当前索引赋值
            }
        }
    }
    System.out.println("排序后的结果"+Arrays.toString(a));
}
 
运行结果

冒泡排序工具类
| 方法 | 返回类型 | 作用 | 参数说明 | 访问权限 | 
|---|---|---|---|---|
| ascengSort(byte[] a) | byte[] | 对byte数组升序排序 | 传入byte数组 | 公开 | 
| ascengSort(byte[] a,int fromIndex,int toIndex) | byte[] | 对byte数组具体索引升序排序 | 传入byte数组,开始索引,结束索引 | 公开 | 
| ascengSort(short[] a) | short[] | 对short数组升序排序 | 传入short数组 | 公开 | 
| ascengSort(short[] a,int fromIndex,int toIndex) | short[] | 对short数组具体索引升序排序 | 传入short数组,开始索引,结束索引 | 公开 | 
| ascengSort(int[] a) | int[] | 对int数组升序排序 | 传入int数组 | 公开 | 
| ascengSort(int[] a,int fromIndex,int toIndex) | int[] | 对int数组具体索引升序排序 | 传入int数组,开始索引,结束索引 | 公开 | 
| ascengSort(long[] a) | long[] | 对long数组升序排序 | 传入long数组 | 公开 | 
| ascengSort(long[] a,int fromIndex,int toIndex) | long[] | 对long数组具体索引升序排序 | 传入long数组,开始索引,结束索引 | 公开 | 
| ascengSort(double[] a) | double[] | 对double数组升序排序 | 传入double数组 | 公开 | 
| ascengSort(double[] a,int fromIndex,int toIndex) | double[] | 对double数具体索引升序排序 | 传入double数组,开始索引,结束索引 | 公开 | 
| ascengSort(float[] a) | float[] | 对float数组升序排序 | 传入float数组 | 公开 | 
| ascengSort(float[] a,int fromIndex,int toIndex) | float[] | 对float数组具体索引升序排序 | 传入float数组,开始索引,结束索引 | 公开 | 
| ascengSort(char[] a) | char[] | 对char数组升序排序 | 传入char数组 | 公开 | 
| ascengSort(char[] a,int fromIndex,int toIndex) | char[] | 对char数组具体索引升序排序 | 传入char数组,开始索引,结束索引 | 公开 | 
| dropSort(byte[] a) | byte[] | 对byte数组降序排序 | 传入byte数组 | 公开 | 
| dropSort(byte[] a, int fromIndex, int toIndex) | byte[] | 对byte数组具体索引降序排序 | 传入byte数组,开始索引,结束索引 | 公开 | 
| dropSort(short[] a) | short[] | 对short数组降序排序 | 传入short数组 | 公开 | 
| dropSort(short[] a, int fromIndex, int toIndex) | short[] | 对short数组具体索引降序排序 | 传入short数组,开始索引,结束索引 | 公开 | 
| dropSort(int[] a) | int[] | 对int数组降序排序 | 传入int数组 | 公开 | 
| dropSort(int[] a, int fromIndex, int toIndex) | int[] | 对int数组具体索引降序排序 | 传入int数组,开始索引,结束索引 | 公开 | 
| dropSort(long[] a) | long[] | 对long数组降序排序 | 传入long数组 | 公开 | 
| dropSort(long[] a, int fromIndex, int toIndex) | long[] | 对long数组具体索引降序排序 | 传入long数组,开始索引,结束索引 | 公开 | 
| dropSort(double[] a) | double[] | 对double数组降序排序 | 传入double数组 | 公开 | 
| dropSort(double[] a, int fromIndex, int toIndex) | double[] | 对double数组具体索引降序排序 | 传入double数组,开始索引,结束索引 | 公开 | 
| dropSort(float[] a) | float[] | 对float数组降序排序 | 传入float数组 | 公开 | 
| dropSort(float[] a, int fromIndex, int toIndex) | float[] | 对float数组具体索引降序排序 | 传入float数组,开始索引,结束索引 | 公开 | 
| dropSort(char[] a) | char[] | 对char数组降序排序 | 传入char数组 | 公开 | 
| dropSort(char[] a, int fromIndex, int toIndex) | char[] | 对char数组具体索引降序排序 | 传入char数组,开始索引,结束索引 | 公开 | 
| rangeCheck(int arrayLength, int fromIndex, int toIndex) | void | 索引范围比较 | 数组长度,开始索引,结束索引 | 私有 | 
package com.sin.demo.utli;
/**
 * @author sin
 * @date 2022/10/31
 * @apiNote
 */
public class BubbleSortUtlis {
    /**
     * 升序排序
     *
     * @param a 传入的数组
     * @return
     */
    public byte[] ascengSort(byte[] a) {
        int aLength = a.length;
        int i, j;
        for (i = 1; i < aLength; i++) {
            for (j = 0; j < aLength - 1; j++) {
                if (a[j] > a[j + 1]) {
                    byte cache = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = cache;
                }
            }
        }
        return a;
    }
    /**
     * 升序排序
     *
     * @param a         传入的数组
     * @param fromIndex 开始元素
     * @param toIndex   结束元素
     * @return
     */
    public byte[] ascengSort(byte[] a, int fromIndex, int toIndex) {
        int aLength = a.length;
        //对索引范围的校验
        this.rangeCheck(aLength, fromIndex, toIndex);
        int cycles = fromIndex - toIndex;
        int i, j;
        for (i = cycles; i < aLength; i++) {
            for (j = fromIndex; j < toIndex; j++) {
                if (a[j] > a[j + 1]) {
                    byte cache = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = cache;
                }
            }
        }
        return a;
    }
    /**
     * 升序排序
     *
     * @param a 传入的数组
     * @return
     */
    public short[] ascengSort(short[] a) {
        int aLength = a.length;
        int i, j;
        for (i = 1; i < aLength; i++) {
            for (j = 0; j < aLength - 1; j++) {
                if (a[j] > a[j + 1]) {
                    short cache = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = cache;
                }
            }
        }
        return a;
    }
    /**
     * 升序排序
     *
     * @param a         传入的数组
     * @param fromIndex 开始元素
     * @param toIndex   结束元素
     * @return
     */
    public short[] ascengSort(short[] a, int fromIndex, int toIndex) {
        int aLength = a.length;
        //对索引范围的校验
        this.rangeCheck(aLength, fromIndex, toIndex);
        int cycles = fromIndex - toIndex;
        int i, j;
        for (i = cycles; i < aLength; i++) {
            for (j = fromIndex; j < toIndex; j++) {
                if (a[j] > a[j + 1]) {
                    short cache = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = cache;
                }
            }
        }
        return a;
    }
    /**
     * 升序排序
     *
     * @param a 传入的数组
     * @return
     */
    public int[] ascengSort(int[] a) {
        int aLength = a.length;
        int i, j;
        for (i = 1; i < aLength; i++) {
            for (j = 0; j < aLength - 1; j++) {
                if (a[j] > a[j + 1]) {
                    int cache = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = cache;
                }
            }
        }
        return a;
    }
    /**
     * 升序排序
     *
     * @param a         传入的数组
     * @param fromIndex 开始元素
     * @param toIndex   结束元素
     * @return
     */
    public int[] ascengSort(int[] a, int fromIndex, int toIndex) {
        int aLength = a.length;
        //对索引范围的校验
        this.rangeCheck(aLength, fromIndex, toIndex);
        int cycles = fromIndex - toIndex;
        int i, j;
        for (i = cycles; i < aLength; i++) {
            for (j = fromIndex; j < toIndex; j++) {
                if (a[j] > a[j + 1]) {
                    int cache = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = cache;
                }
            }
        }
        return a;
    }
    /**
     * 升序排序
     *
     * @param a 传入的数组
     * @return
     */
    public long[] ascengSort(long[] a) {
        int aLength = a.length;
        int i, j;
        for (i = 1; i < aLength; i++) {
            for (j = 0; j < aLength - 1; j++) {
                if (a[j] > a[j + 1]) {
                    long cache = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = cache;
                }
            }
        }
        return a;
    }
    /**
     * 升序排序
     *
     * @param a         传入的数组
     * @param fromIndex 开始元素
     * @param toIndex   结束元素
     * @return
     */
    public long[] ascengSort(long[] a, int fromIndex, int toIndex) {
        int aLength = a.length;
        //对索引范围的校验
        this.rangeCheck(aLength, fromIndex, toIndex);
        int cycles = fromIndex - toIndex;
        int i, j;
        for (i = cycles; i < aLength; i++) {
            for (j = fromIndex; j < toIndex; j++) {
                if (a[j] > a[j + 1]) {
                    long cache = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = cache;
                }
            }
        }
        return a;
    }
    /**
     * 升序排序
     *
     * @param a 传入的数组
     * @return
     */
    public double[] ascengSort(double[] a) {
        int aLength = a.length;
        int i, j;
        for (i = 1; i < aLength; i++) {
            for (j = 0; j < aLength - 1; j++) {
                if (a[j] > a[j + 1]) {
                    double cache = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = cache;
                }
            }
        }
        return a;
    }
    /**
     * 升序排序
     *
     * @param a         传入的数组
     * @param fromIndex 开始元素
     * @param toIndex   结束元素
     * @return
     */
    public double[] ascengSort(double[] a, int fromIndex, int toIndex) {
        int aLength = a.length;
        //对索引范围的校验
        this.rangeCheck(aLength, fromIndex, toIndex);
        int cycles = fromIndex - toIndex;
        int i, j;
        for (i = cycles; i < aLength; i++) {
            for (j = fromIndex; j < toIndex; j++) {
                if (a[j] > a[j + 1]) {
                    double cache = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = cache;
                }
            }
        }
        return a;
    }
    /**
     * 升序排序
     *
     * @param a 传入的数组
     * @return
     */
    public float[] ascengSort(float[] a) {
        int aLength = a.length;
        int i, j;
        for (i = 1; i < aLength; i++) {
            for (j = 0; j < aLength - 1; j++) {
                if (a[j] > a[j + 1]) {
                    float cache = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = cache;
                }
            }
        }
        return a;
    }
    /**
     * 升序排序
     *
     * @param a         传入的数组
     * @param fromIndex 开始元素
     * @param toIndex   结束元素
     * @return
     */
    public float[] ascengSort(float[] a, int fromIndex, int toIndex) {
        int aLength = a.length;
        //对索引范围的校验
        this.rangeCheck(aLength, fromIndex, toIndex);
        int cycles = fromIndex - toIndex;
        int i, j;
        for (i = cycles; i < aLength; i++) {
            for (j = fromIndex; j < toIndex; j++) {
                if (a[j] > a[j + 1]) {
                    float cache = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = cache;
                }
            }
        }
        return a;
    }
    /**
     * 升序排序
     *
     * @param a 传入的数组
     * @return
     */
    public char[] ascengSort(char[] a) {
        int aLength = a.length;
        int i, j;
        for (i = 1; i < aLength; i++) {
            for (j = 0; j < aLength - 1; j++) {
                if (a[j] > a[j + 1]) {
                    char cache = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = cache;
                }
            }
        }
        return a;
    }
    /**
     * 升序排序
     *
     * @param a         传入的数组
     * @param fromIndex 开始元素
     * @param toIndex   结束元素
     * @return
     */
    public char[] ascengSort(char[] a, int fromIndex, int toIndex) {
        int aLength = a.length;
        //对索引范围的校验
        this.rangeCheck(aLength, fromIndex, toIndex);
        int cycles = fromIndex - toIndex;
        int i, j;
        for (i = cycles; i < aLength; i++) {
            for (j = fromIndex; j < toIndex; j++) {
                if (a[j] > a[j + 1]) {
                    char cache = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = cache;
                }
            }
        }
        return a;
    }
    /**
     * 降序排序
     *
     * @param a 传入的数组
     * @return
     */
    public byte[] dropSort(byte[] a) {
        int aLength = a.length;
        int i, j;
        for (i = 1; i < aLength; i++) {
            for (j = 0; j < aLength - 1; j++) {
                if (a[j] < a[j + 1]) {
                    byte cache = a[j + 1];
                    a[j + 1] = a[j];
                    a[j] = cache;
                }
            }
        }
        return a;
    }
    /**
     * 降序排序
     *
     * @param a         传入的数组
     * @param fromIndex 开始元素
     * @param toIndex   结束元素
     * @return
     */
    public byte[] dropSort(byte[] a, int fromIndex, int toIndex) {
        int aLength = a.length;
        //对索引范围的校验
        this.rangeCheck(aLength, fromIndex, toIndex);
        int cycles = fromIndex - toIndex;
        int i, j;
        for (i = cycles; i < aLength; i++) {
            for (j = fromIndex; j < toIndex; j++) {
                if (a[j] < a[j + 1]) {
                    byte cache = a[j + 1];
                    a[j + 1] = a[j];
                    a[j] = cache;
                }
            }
        }
        return a;
    }
    /**
     * 降序排序
     *
     * @param a 传入的数组
     * @return
     */
    public short[] dropSort(short[] a) {
        int aLength = a.length;
        int i, j;
        for (i = 1; i < aLength; i++) {
            for (j = 0; j < aLength - 1; j++) {
                if (a[j] < a[j + 1]) {
                    short cache = a[j + 1];
                    a[j + 1] = a[j];
                    a[j] = cache;
                }
            }
        }
        return a;
    }
    /**
     * 降序排序
     *
     * @param a         传入的数组
     * @param fromIndex 开始元素
     * @param toIndex   结束元素
     * @return
     */
    public short[] dropSort(short[] a, int fromIndex, int toIndex) {
        int aLength = a.length;
        //对索引范围的校验
        this.rangeCheck(aLength, fromIndex, toIndex);
        int cycles = fromIndex - toIndex;
        int i, j;
        for (i = cycles; i < aLength; i++) {
            for (j = fromIndex; j < toIndex; j++) {
                if (a[j] < a[j + 1]) {
                    short cache = a[j + 1];
                    a[j + 1] = a[j];
                    a[j] = cache;
                }
            }
        }
        return a;
    }
    /**
     * 降序排序
     *
     * @param a 传入的数组
     * @return
     */
    public int[] dropSort(int[] a) {
        int aLength = a.length;
        int i, j;
        for (i = 1; i < aLength; i++) {
            for (j = 0; j < aLength - 1; j++) {
                if (a[j] < a[j + 1]) {
                    int cache = a[j + 1];
                    a[j + 1] = a[j];
                    a[j] = cache;
                }
            }
        }
        return a;
    }
    /**
     * 降序排序
     *
     * @param a         传入的数组
     * @param fromIndex 开始元素
     * @param toIndex   结束元素
     * @return
     */
    public int[] dropSort(int[] a, int fromIndex, int toIndex) {
        int aLength = a.length;
        //对索引范围的校验
        this.rangeCheck(aLength, fromIndex, toIndex);
        int cycles = fromIndex - toIndex;
        int i, j;
        for (i = cycles; i < aLength; i++) {
            for (j = fromIndex; j < toIndex; j++) {
                if (a[j] < a[j + 1]) {
                    int cache = a[j + 1];
                    a[j + 1] = a[j];
                    a[j] = cache;
                }
            }
        }
        return a;
    }
    /**
     * 降序排序
     *
     * @param a 传入的数组
     * @return
     */
    public long[] dropSort(long[] a) {
        int aLength = a.length;
        int i, j;
        for (i = 1; i < aLength; i++) {
            for (j = 0; j < aLength - 1; j++) {
                if (a[j] < a[j + 1]) {
                    long cache = a[j + 1];
                    a[j + 1] = a[j];
                    a[j] = cache;
                }
            }
        }
        return a;
    }
    /**
     * 降序排序
     *
     * @param a         传入的数组
     * @param fromIndex 开始元素
     * @param toIndex   结束元素
     * @return
     */
    public long[] dropSort(long[] a, int fromIndex, int toIndex) {
        int aLength = a.length;
        //对索引范围的校验
        this.rangeCheck(aLength, fromIndex, toIndex);
        int cycles = fromIndex - toIndex;
        int i, j;
        for (i = cycles; i < aLength; i++) {
            for (j = fromIndex; j < toIndex; j++) {
                if (a[j] < a[j + 1]) {
                    long cache = a[j + 1];
                    a[j + 1] = a[j];
                    a[j] = cache;
                }
            }
        }
        return a;
    }
    /**
     * 降序排序
     *
     * @param a 传入的数组
     * @return
     */
    public double[] dropSort(double[] a) {
        int aLength = a.length;
        int i, j;
        for (i = 1; i < aLength; i++) {
            for (j = 0; j < aLength - 1; j++) {
                if (a[j] < a[j + 1]) {
                    double cache = a[j + 1];
                    a[j + 1] = a[j];
                    a[j] = cache;
                }
            }
        }
        return a;
    }
    /**
     * 降序排序
     *
     * @param a         传入的数组
     * @param fromIndex 开始元素
     * @param toIndex   结束元素
     * @return
     */
    public double[] dropSort(double[] a, int fromIndex, int toIndex) {
        int aLength = a.length;
        //对索引范围的校验
        this.rangeCheck(aLength, fromIndex, toIndex);
        int cycles = fromIndex - toIndex;
        int i, j;
        for (i = cycles; i < aLength; i++) {
            for (j = fromIndex; j < toIndex; j++) {
                if (a[j] < a[j + 1]) {
                    double cache = a[j + 1];
                    a[j + 1] = a[j];
                    a[j] = cache;
                }
            }
        }
        return a;
    }
    /**
     * 降序排序
     *
     * @param a 传入的数组
     * @return
     */
    public float[] dropSort(float[] a) {
        int aLength = a.length;
        int i, j;
        for (i = 1; i < aLength; i++) {
            for (j = 0; j < aLength - 1; j++) {
                if (a[j] < a[j + 1]) {
                    float cache = a[j + 1];
                    a[j + 1] = a[j];
                    a[j] = cache;
                }
            }
        }
        return a;
    }
    /**
     * 降序排序
     *
     * @param a         传入的数组
     * @param fromIndex 开始元素
     * @param toIndex   结束元素
     * @return
     */
    public float[] dropSort(float[] a, int fromIndex, int toIndex) {
        int aLength = a.length;
        //对索引范围的校验
        this.rangeCheck(aLength, fromIndex, toIndex);
        int cycles = fromIndex - toIndex;
        int i, j;
        for (i = cycles; i < aLength; i++) {
            for (j = fromIndex; j < toIndex; j++) {
                if (a[j] < a[j + 1]) {
                    float cache = a[j + 1];
                    a[j + 1] = a[j];
                    a[j] = cache;
                }
            }
        }
        return a;
    }
    /**
     * 降序排序
     *
     * @param a 传入的数组
     * @return
     */
    public char[] dropSort(char[] a) {
        int aLength = a.length;
        int i, j;
        for (i = 1; i < aLength; i++) {
            for (j = 0; j < aLength - 1; j++) {
                if (a[j] < a[j + 1]) {
                    char cache = a[j + 1];
                    a[j + 1] = a[j];
                    a[j] = cache;
                }
            }
        }
        return a;
    }
    /**
     * 降序排序
     *
     * @param a         传入的数组
     * @param fromIndex 开始元素
     * @param toIndex   结束元素
     * @return
     */
    public char[] dropSort(char[] a, int fromIndex, int toIndex) {
        int aLength = a.length;
        //对索引范围的校验
        this.rangeCheck(aLength, fromIndex, toIndex);
        int cycles = fromIndex - toIndex;
        int i, j;
        for (i = cycles; i < aLength; i++) {
            for (j = fromIndex; j < toIndex; j++) {
                if (a[j] < a[j + 1]) {
                    char cache = a[j + 1];
                    a[j + 1] = a[j];
                    a[j] = cache;
                }
            }
        }
        return a;
    }
    /**
     * 索引范围比较
     *
     * @param arrayLength 数组长度
     * @param fromIndex   开始索引
     * @param toIndex     结束索引
     */
    private void rangeCheck(int arrayLength, int fromIndex, int toIndex) {
        /**
         * 如果开始索引比结束索引大
         * 则排除非法参数异常
         */
        if (fromIndex > toIndex) {
            throw new IllegalArgumentException(
                    "开始索引(" + fromIndex + ") > 结束索引(" + toIndex + ")");
        }
        /**
         * 如果开始索引小于0
         * 则抛出数组索引越界异常
         */
        if (fromIndex < 0) {
            throw new ArrayIndexOutOfBoundsException(fromIndex);
        }
        /**
         * 如果结束索引小于0
         * 则抛出数组索引越界异常
         */
        if (toIndex > arrayLength) {
            throw new ArrayIndexOutOfBoundsException(toIndex);
        }
    }
}
 
BubbleSortUtlis工具类测试
//实例化工具类
BubbleSortUtlis bubbleSortUtlis = new BubbleSortUtlis();
 
int类型数组升序排序
@Test
public void testIntAscengSort() {
    int[] a = {2,5,3,8,1,9,23,11,6};
    System.out.println("排序前"+Arrays.toString(a));
    bubbleSortUtlis.ascengSort(a);
    System.out.println("排序后"+Arrays.toString(a));
}
 
测试结果

int类型数组对具体元素升序排序
@Test
public void testIntAscengSort() {
    int[] a = {2,5,3,8,1,9,23,11,6};
    System.out.println("排序前"+Arrays.toString(a));
    bubbleSortUtlis.ascengSort(a,3,7);
    System.out.println("排序后"+Arrays.toString(a));
}
 
测试结果

int类型降序排序
@Test
public void testIntAscengSort() {
    int[] a = {2,5,3,8,1,9,23,11,6};
    System.out.println("排序前"+Arrays.toString(a));
    bubbleSortUtlis.dropSort(a);
    System.out.println("排序后"+Arrays.toString(a));
}
 
测试结果

int类型对具体元素降序排序
@Test
public void testIntAscengSort() {
    int[] a = {2,5,3,8,1,9,23,11,6};
    System.out.println("排序前"+Arrays.toString(a));
    bubbleSortUtlis.dropSort(a,2,5);
    System.out.println("排序后"+Arrays.toString(a));
}
 
测试结果

char类型数组升序排序
 @Test
    public void testCharAscengSort() {
        char[] a = {'a', 'v', 'd', 'e', 'f', 'c', 'b'};
        System.out.println("排序前"+Arrays.toString(a));
        bubbleSortUtlis.ascengSort(a);
        System.out.println("排序后"+Arrays.toString(a));
    }
 
结束结果
 
char类型数组对具体元素升序排序
@Test
public void testCharAscengSort() {
    char[] a = {'a', 'v', 'd', 'e', 'f', 'c', 'b'};
    System.out.println("排序前"+Arrays.toString(a));
    bubbleSortUtlis.ascengSort(a,2,5);
    System.out.println("排序后"+Arrays.toString(a));
}
 
测试结果

char类型数组降序排序
@Test
public void testCharAscengSort() {
    char[] a = {'a', 'v', 'd', 'e', 'f', 'c', 'b'};
    System.out.println("排序前"+Arrays.toString(a));
    bubbleSortUtlis.dropSort(a);
    System.out.println("排序后"+Arrays.toString(a));
}
 
测试结果

char类型数组对具体元素降序排序
@Test
public void testCharAscengSort() {
    char[] a = {'a', 'v', 'd', 'e', 'f', 'c', 'b'};
    System.out.println("排序前"+Arrays.toString(a));
    bubbleSortUtlis.dropSort(a,2,4);
    System.out.println("排序后"+Arrays.toString(a));
}
 
测试结果







![[carla入门教程]-1 安装carla环境](https://img-blog.csdnimg.cn/e2786b708614436782c033adcb0486c6.png)












