Sorting algorithms/Shell sort: Difference between revisions

m
(Added AppleScript implementation)
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 int(inc * 5.0 // 11)</lang>
 
{{output}}
data = [22, 7, 2, -5, 8, 4]
<pre>
shell(data)
print>>> data #= [-522, 27, 42, 7-5, 8, 224]</lang>
def>>> shell(seqdata):
>>> print(data)
data = [22-5, 72, 24, -57, 8, 422]
</pre>
 
=={{header|Racket}}==