排序算法-冒泡排序(工具类)

冒泡排序

什么是冒泡排序

冒泡排序(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));
}
测试结果

在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

陆卿之SIN

你的鼓励将是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值