Anonymous user
Sorting algorithms/Shell sort: Difference between revisions
m
→{{header|Python}}: Cleanup
(Added AppleScript implementation) |
m (→{{header|Python}}: Cleanup) |
||
Line 2,468:
This method sorts in place.
If you want to preserve your unsorted list, copy it first.
<lang python>def shell(seq):
def shell(seq):▼
inc = len(seq) // 2
while inc:
for i, el in enumerate(seq[inc:], inc):
while i >= inc and seq[i - inc] > el:
seq[i] = seq[i - inc]
i -= inc
seq[i] = el
inc = 1 if inc == 2 else
{{output}}
data = [22, 7, 2, -5, 8, 4]▼
<pre>
>>> print(data)
</pre>
=={{header|Racket}}==
|