Giter Site home page Giter Site logo

lsgwr / algorithms Goto Github PK

View Code? Open in Web Editor NEW
325.0 325.0 106.0 169.62 MB

算法学习与总结,包括慕课网刘宇波老师、算法竞赛入门经典、挑战程序设计竞赛、算法竞赛宝典等

License: Other

C++ 30.32% Java 69.34% Pascal 0.13% Batchfile 0.04% Python 0.03% C 0.01% CMake 0.13%
algorithms imooc leetcode liuyubobobo

algorithms's Introduction

algorithms

慕课网刘宇波老师算法课程在学习时自己的学习笔记.后来又加了些其他的算法书籍和课程的学习

在线访问链接: https://www.processon.com/view/link/5e073b2ee4b0c1ff2113ed77

数据结构与算法学习思维导图

algorithms's People

Contributors

lsgwr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

algorithms's Issues

Part1Basic/JAVA/src/main/java/Chapter2SortingBasic/Section6InsertionSortOptimize/InsertionSort.java,发现一个bug

public static void sort(Comparable[] arr) {
        int n = arr.length;
        // 注意下标从1开始,不停往前比较,下标为0的元素默认有效
        for (int i = 1; i < n; ++i) {
            // 先把起始位置的元素暂存
            Comparable tmp = arr[i];
            // 从位置i开始,从前挨个比较(前面已经是有序地了,这个是前提),一直比较到前面的某个元素比自己小就停下
            for (int j = i; j > 0; j--) {
                if (tmp.compareTo(arr[j - 1]) < 0) {
                    // 起始位置元素比前面的小,就把前面的值附到后面来元素上
                    arr[j] = arr[j - 1];
                } else {
                    // 一直到j前面的元素j-1小于tmp了,说明升序排列完成,把之前存的起始位置元素tmp插入到此处即可
                    arr[j] = tmp;
                    break;
                }
            }

        }

当j=0时,不会进入for循环。arr[j] = tmp;应该写在内部循环的外面。

public static void sort(Comparable[] arr) {
        int n = arr.length;
        // 注意下标从1开始,不停往前比较,下标为0的元素默认有效
        for (int i = 1; i < n; ++i) {
            // 先把起始位置的元素暂存
            Comparable tmp = arr[i];
            int j = i;
            // 从位置i开始,从前挨个比较(前面已经是有序地了,这个是前提),一直比较到前面的某个元素比自己小就停下
            for (; j > 0; j--) {
                if (tmp.compareTo(arr[j - 1]) < 0) {
                    // 起始位置元素比前面的小,就把前面的值附到后面来元素上
                    arr[j] = arr[j - 1];
                } else {
                    // 一直到j前面的元素j-1小于tmp了,说明升序排列完成,把之前存的起始位置元素tmp插入到此处即可
                    break;
                }
            }
            arr[j] = tmp;

        }
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.