发表于: 2017-07-16 23:16:13

1 1176


一。今天完成的事情

    对于昨天重新组合逻辑之后,对于公司的存储放施主把共死新建的桑表的属性放到一个类里面去,然后从这个类里面重新insert数据,其中嵌套插入数据,保持事物。

    但上面还没有实现,所以还在修改中。


    好友常见的集中排序,最基本的冒泡排序是一定要会使用java实现的。然后使用了之后

     知道实现的原理和优化,还有时间复杂度。

    

public class BubbleSort {

    public static void bubbleSort(int[] a) {

        int temp;

        for (int i = 0; i < a.length - 1; ++i) {

            for (int j = a.length - 1; j > i; --j) {

                if (a[j] < a[j - 1]) {

                    temp = a[j];

                    a[j] = a[j - 1];

                    a[j - 1] = temp;

                }

            }

        }

    }

    public static void main(String[] args) {

        int a[] = { 49,38,65,97,76,13,27,49};

        bubbleSort(a);

        System.out.println(Arrays.toString(a));

    }

优化,加入一个判断值,可以加一个boolean类型的就行,也可以自己设置一个标记的break来实现。

public class SelectSort {

    public static void selectSort(int[] a) {

        if (a == null || a.length <= 0) {

            return;

        }

        for (int i = 0; i < a.length; i++) {

            int temp = a[i];

            int flag = i; // 将当前下标定义为最小值下标

            for (int j = i + 1; j < a.length; j++) {

                if (a[j] < temp) {// a[j] < temp 从小到大排序;a[j] > temp 从大到小排序

                    temp = a[j];

                    flag = j; // 如果有小于当前最小值的关键字将此关键字的下标赋值给flag

                }

            }

            if (flag != i) {

                a[flag] = a[i];

                a[i] = temp;

            }

        }

    }

    public static void main(String[] args) {

        int a[] = { 49,38,65,97,76,13,27,49 };

        selectSort(a);

        System.out.println(Arrays.toString(a));

    }

二。遇到的问题:无

三、明天计划的事情:

四、收获:好好学习!


返回列表 返回列表
评论

    分享到