Giter Club home page Giter Club logo

Comments (6)

ZQPei avatar ZQPei commented on May 29, 2024

您好,可以说一下错在哪里吗?

from sorting_visualization.

Baobaobear avatar Baobaobear commented on May 29, 2024

内循环步长是D没有问题,但外循环步长是1才对,请参阅 Shellsort wiki

from sorting_visualization.

AlterWL avatar AlterWL commented on May 29, 2024

我认为应该是这样,运行没问题:

   Length = ds.length
    D = Length // 2
    while D > 0:
        c = 0
        while c < D:
            i = c + D
            while i < Length:
                tmp = ds.data[i]
                j = i
                while j>c and ds.data[j-D]>tmp:
                    ds.SetVal(j, ds.data[j-D])
                    j -= D
                ds.SetVal(j, tmp)
                i+=D
            c += 1
        D//=2

但是建议用更简洁的形式:

Length = ds.length
    col_num = Length // 2 # 初始列数
    # print(ds.data)
    while col_num > 0: # 逐渐减少列数,最后减少到1列
        for c in range(col_num): # 对第c列进行插入排序
            for cp in range(c+col_num,Length,col_num):
                tmp = ds.data[cp]
                j=cp
                while j>c and ds.data[j-col_num]>tmp: # 寻找插入位置
                    ds.SetVal(j, ds.data[j-col_num])
                    j -= col_num
                ds.SetVal(j, tmp)
        # print(ds.data)
        col_num //= 2 # 列数减半

from sorting_visualization.

Baobaobear avatar Baobaobear commented on May 29, 2024

@AlterWL 你写成三重循环更不对了,请看我给的链接

from sorting_visualization.

AlterWL avatar AlterWL commented on May 29, 2024

改了一下,这样对吗?

    Length = ds.length
    col_num = Length // 2 # 初始列数
    while col_num > 0: # 逐渐减少列数,最后减少到1列
        for cp in range(col_num,Length):
            tmp = ds.data[cp]
            j=cp
            while j>=col_num and ds.data[j-col_num]>tmp: # 寻找插入位置
                ds.SetVal(j, ds.data[j-col_num])
                j -= col_num
            ds.SetVal(j, tmp)
        col_num //= 2 # 列数减半

from sorting_visualization.

Baobaobear avatar Baobaobear commented on May 29, 2024

这个看起来是对的

from sorting_visualization.

Related Issues (7)

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.