链接: https://caiyun.139.com/m/i?145CFLgRywJF8  提取码:qwAV  复制内容打开和彩云手机APP,操作更方便哦

MaoPao_Array

package sdkj.spring.util.SuanFa;

//数组冒泡
public class MaoPao_Array {

    /*public static void main(String[] args) {

        int[] a = {8,4,66,12,3,74,54,5,14,35};
        int[] ints = maoPao(a);
    }*/
    public /*static*/ int[] maoPao(int[] ns){

        int[] nums = ns;
        for (int i = 0; i < nums.length; i++) {

            for (int j = 0; j <= i; j++) {

                if (nums[i] < nums[j]){

                    int temp = nums[j];
                    nums[j] = nums[i];
                    nums[i] = temp;
                }
            }
        }
        /*for (int num : nums) {
            System.out.print(num+" ");
        }
        System.out.println();*/
        return nums;
    }
}

QuickSort_Array

package sdkj.spring.util.SuanFa;

//数组快排
public class QuickSort_Array {

    /*public static void main(String[] args) {

        int[] a = {8,4,66,12,3,74,54,5,14,35};
        int[] ints = quickSort(a,0,9);
        for (int num : ints) {
            System.out.print(num+" ");
        }
        System.out.println();
    }*/
    public /*static*/ int[] quickSort(int[] ns,int s,int e){

        int[] nums = ns;
        int start = s;
        int end = e;
        int zys = nums[start];
        while (start < end){

            //找小的
            while (start < end && nums[end] >= zys)
                end--;
            swap(nums,start,end);
            //找大的
            while (start < end && nums[start] <= zys)
                start++;
            swap(nums,start,end);
        }
        if (start > s)
            quickSort(nums,s,start-1);
        if (e > end)
            quickSort(nums,end+1,e);
        return nums;
    }

    private /*static*/ void swap(int[] nums, int start, int end) {

        int temp = nums[end];
        nums[end] = nums[start];
        nums[start] = temp;
    }
}

Spring类的底层equals方法代码

    public boolean equals(Object anObject) {

        //比较内存地址
        if (this == anObject) {
            return true;
        }
        //instanceof ⽤来测试⼀个对象是否为⼀个类的实例
        if (anObject instanceof String) {
            String anotherString = (String)anObject;
            int n = value.length;
            //算法:先比较长度,长度不一样直接不比较了,一样就挨个比较字符,发现不一样直接return false
            if (n == anotherString.value.length) {
                char v1[] = value;
                char v2[] = anotherString.value;
                int i = 0;
                while (n-- != 0) {
                    if (v1[i] != v2[i])
                        return false;
                    i++;
                }
                return true;
            }
        }
        return false;
    }