Comments (6)
您好,可以说一下错在哪里吗?
from sorting_visualization.
内循环步长是D没有问题,但外循环步长是1才对,请参阅 Shellsort wiki
from sorting_visualization.
我认为应该是这样,运行没问题:
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.
@AlterWL 你写成三重循环更不对了,请看我给的链接
from sorting_visualization.
改了一下,这样对吗?
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.
这个看起来是对的
from sorting_visualization.
Related Issues (7)
- 重复部分可以不用再排序 HOT 1
- 这个堆稍微快点 HOT 1
- 请教一下这个mark1和mark2到底有啥用 HOT 1
- 单独运行排序算法模块出错 HOT 1
- 定义长度为10但填充的柱状图仅为9,有一个被填充为背景色 HOT 1
- question
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sorting_visualization.