Coder Social home page Coder Social logo

Comments (2)

liuwei1993 avatar liuwei1993 commented on August 15, 2024

上述算法由于从start开始比较导致效率并不比楼主高,甚至在近乎有序的数组中排序效率和完全无序序列相同,改进后则可以通过System.arraycopy()方法提升性能

   void insertSort(int[] data) {
        int length = data.length;
        for (int i = 1; i < length; i++) {
            int tmp = data[i];
            int j = i;
            while (j > 0 && data[j-1] > tmp) j--;
            System.arraycopy(data, j, data, j + 1, i - j);
            data[j] = tmp;
       }
   }

但此时近乎有序的序列排序时效率正常,完全无序序列排序时长比楼主多了1/3,目前未找明原因,我个人认为可能是我的方法还存在一些影响性能的缺陷,使用System.arraycopy方法应该是有助于性能提升的。我会继续寻找原因

from play-with-algorithms.

liuyubobobo avatar liuyubobobo commented on August 15, 2024

非常赞!不过使用标准库函数带来的效率提升不是这个课程的重点,所以在这里并不采纳你的建议。敬请谅解:)

from play-with-algorithms.

Related Issues (20)

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.