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

news2024/9/19 10:49:30

冒泡排序

什么是冒泡排序

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

测试结果

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2399.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

C - Bricks and Bags,E - Hanging Hearts,H-Leonard的子序列_树状数组优化dp,B - Hash 河南省赛

14天阅读挑战赛 C - Bricks and Bags 情况考虑少了&#xff0c;以为把最大值和最小值单独放在两个包里是最优的&#xff0c;其实不是&#xff0c;应该是分别枚举i&#xff0c;分别和最大值或最小值单独放在两个包里&#xff0c;然后去更新答案 #include<bits/stdc.h> …

基于stm32 ESP8266WiFi模块的基本通信

文章目录前言一、什么是ESP8266&#xff1f;二、ESP8266常用指令集三、模块的配置 及 指令的使用四、程序设计前言 本篇涉及到的模块与工具为&#xff1a; 1. ATK-ESP8266wifi模块 2. USB-UART模块 3. 串口调试助手 提取链接&#xff1a;https://pan.baidu.com/s/17xRlpnjp8j-…

软考下午题第2题——E-R图 UML图 逻辑结构设计-示题与解析

下午的第二题主要是找【属性】【主键】【外键】【候选键】之间的关系。 候选键&#xff1a;属性或者是属性组合&#xff0c;其值能够唯一地标识一个元组 主键&#xff1a;在一个关系中可能有多个候选键&#xff0c;从中选择一个作为主键 外键&#xff1a;如果一个关系中的属性或…

【JavaWeb】会话跟踪技术Cookie与Session原始真解

文章目录1 什么是会话&#xff1f;2 Cookie技术2.1 Cookie简介2.2 Cookie的理解与创建2.3 服务器获取Cookie与Cookie的修改2.4 Cookie的生命控制与生命周期2.5 Cookie有效路径Path设置3 Session会话技术3.1 初探Session3.2 Session的创建、获取与基本使用3.3 Session的生命控制…

使用Python的smtplib模块发送带附件的邮件

上一篇文章《使用Python的smtplib模块发送简单邮件》介绍了调用smtplib模块发送包含简单内容的邮件&#xff0c;本文继续学习参考文献1中的发送带附件的邮件的示例代码&#xff0c;同时由于参考文献1中的带附件邮件中并没有邮件附件&#xff0c;而仅仅是邮件内容中关联的内嵌资…

哪款半入耳式蓝牙耳机音质好?音质比较好的半入耳式蓝牙耳机推荐

半入耳式的蓝牙耳机相比入耳式的要舒适许多&#xff0c;佩戴更加的舒适透气&#xff0c;近年来&#xff0c;市面上的蓝牙耳机鱼龙混杂&#xff0c;人们选购蓝牙耳机对音质有一定的要求&#xff0c;下面是我整理的四款音质高的半入耳式蓝牙耳机&#xff0c;可以参考参考。 一、…

[carla入门教程]-1 安装carla环境

本专栏教程将记录我从安装carla到调用carla的pythonAPI进行车辆操控的全流程,带领大家从安装carla开始,到最终能够熟练使用carla仿真环境进行传感器数据采集和车辆控制. 第一节 carla 仿真环境的安装 准备工作: 在本节教程之前,需要大家安装ubuntu18.04以上的系统,并且安装对…

【MATLAB教程案例33】基于高斯混合模型的视频背景提取算法的matlab仿真实现

FPGA教程目录 MATLAB教程目录 本课程学习成果预览(左图是原始视频,右图是背景提取结果) 目录 1.软件版本 2.基于高斯混合模型的视频背景

顺序表和链表

顺序表和链表1.线性表2.顺序表2.1 概念和结构2.2 接口实现2.3 顺序表的问题及思考3.链表3.1 链表的概念和结构3.2 链表的分类3.3 链表的实现3.4 双向链表的实现4. 顺序表和链表的区别和联系1.线性表 线性表是n个具有相同特性的数据元素的有限序列。线性表是一种在实际中广泛使…

Qt 添加第三方字体库

Qt字体库默认主持操作系统所有的字体库&#xff0c;但是设计师一般喜欢比如思源字体&#xff0c;但是咱们的操作系统没有安装&#xff0c;在其他没有安装第三方字体库的电脑上运行&#xff0c;就达不到设计师最初设计的观感。这篇博客介绍Qt如何第三方字体库&#xff0c;以思源…

HTML【基础篇】

HTML【基础篇】&#x1f34e;一.HTML结构&#x1f352;1.1认识HTML标签&#x1f352;1.2HTML文件基本结构&#x1f352;1.3标签层次结构&#x1f352;1.4快速生成代码框架&#x1f34e;二.HTML常见标签&#x1f352;1.1注释标签&#x1f352;1.2标题标签&#xff08;h1-h6&…

用ADSelfService Plus更新Windows缓存的凭证

研究显示&#xff0c;帮助台技术员收到的所有电话中高达30%是因为遗忘了密码。当帮助台技术员处理大量此类电话时&#xff0c;对于来自远程的用户请求就无能为力了。这些用户使用本地缓存的Active Directory凭证来登录其机器。当该用户离开办公室时&#xff0c;帮助台技术员无法…

京东云开发者|ElasticSearch降本增效常见的方法

Elasticsearch在db_ranking 的排名又&#xff08;双叒叕&#xff09;上升了一位,如图1-1所示;由此可见es在存储领域已经蔚然成风且占有非常重要的地位。 随着Elasticsearch越来越受欢迎&#xff0c;企业花费在ES建设上的成本自然也不少。那如何减少ES的成本呢&#xff1f;今天…

某大厂软件测试岗一面笔试题+二面问答题面试经验分享

目录 某大软件测试厂笔试题 选择题 二面 某大软件测试厂笔试题 判断题(Y对&#xff0c;N错) 1.软件测试的目的是尽可能多的找出软件的缺陷。(Y) 2.Beta测试是验收测试的一种。(Y) 3.验收测试是由最终用户来实施的。(N) 4.项目立项前测试人员不需要提交任何工件。(Y) 5…

20 | 如何处理normal.mod not found

目录1 现象2 解决思路2.1 通过命令修复2.2 通过工具修复2.3 通过快照还原3 实际操作3.1 通过命令修复3.1.1 ls3.1.2 ls (hd0,X)/3.1.3 执行命令3.1.4 其他命令3.2 通过工具修复3.2.1 通过liveCD模式3.2.2 安装Boot-Repair3.2.3 修复3.3 通过快照还原1 现象 提示&#xff1a;ER…

YOLO9000: Better, Faster, Stronger (Yolov2)论文详细解读

目录前言1. Better&#xff08;更准&#xff09;2. Faster&#xff08;更快&#xff09;3. Stronger&#xff08;更壮&#xff09;前言 对应YOLOv1论文解读&#xff1a;You Only Look Once: Unified, Real-Time Object Detection&#xff08;Yolov1&#xff09; 论文详细解读 …

带你着手「Servlet」

⭐️前言⭐️ 有了前边文章为我们奠定下的网络基础&#xff0c;我们就可以开始学习Servlet的知识了&#xff0c;在部署一个Java的Servlet程序时&#xff0c;必须要有的开发工具是Tomcat,需要自行完成Tomcat的配置&#xff0c;并掌握maven仓库的配置方法&#xff0c;下边我们也…

windows下搭建mindspore的编译环境

rugwindows 10下安装mindpsore环境&#xff0c;需要visual studio 2019及以上&#xff0c;cmake, python 也可以从上面下载mindspore编译依赖的软件。 visual studioan安装时需注意 然后再安装cmake,git&#xff0c;安装好之后设置检查环境变量&#xff0c;缺失的要补上 系统…

WEB静态网页设计与制作——我的美丽家乡邢台

家乡旅游景点网页作业制作 网页代码运用了DIV盒子的使用方法&#xff0c;如盒子的嵌套、浮动、margin、border、background等属性的使用&#xff0c;外部大盒子设定居中&#xff0c;内部左中右布局&#xff0c;下方横向浮动排列&#xff0c;大学学习的前端知识点和布局方式都有…

【数据结构】顺序表OJ

文章目录0. 前言1. 移除元素2. 删除有序数组中的重复项3. 合并两个有序数组4. 结语0. 前言 在上篇博客中&#xff0c;我们使用C语言实现了顺序表。其中我们也对顺序表的接口进行了完整的实现。但是光实现不够&#xff0c;还是需要题目来练习。于是今天我就为大家带来顺序表的三…