-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.py
More file actions
35 lines (33 loc) · 907 Bytes
/
shell.py
File metadata and controls
35 lines (33 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
def shell_sort(lists):
# 希尔排序
count = len(lists)
step = 2
group = count // step
print(group)
while group > 0:
for i in range(0, group):
j = i + group
while j < count:
k = j - group
key = lists[j]
while k >= 0:
if lists[k] > key:
lists[k + group] = lists[k]
print(lists[k],key)
lists[k] = key
else:
print('----',lists[k],key)
k -= group
print(group)
print(lists)
j += group
group //= step
print(step,group)
return lists
def main():
arr = [661, 10, 666, 511, 20, 555, 444, ]
print(arr)
shell_sort(arr)
print(arr)
if __name__ == '__main__':
main()