Sorting algorithms/Shell sort: Difference between revisions

Added Wren
mNo edit summary
(Added Wren)
Line 3,129:
 
[[/Whitespace|Implementation in Whitespace]].
 
=={{header|Wren}}==
Based on the Wikipedia article pseudo-code.
<lang ecmascript>var shellSort = Fn.new { |a|
var n = a.count
var gaps = [701, 301, 132, 57, 23, 10, 4, 1]
for (gap in gaps) {
if (gap < n) {
for (i in gap...n) {
var t = a[i]
var j = i
while (j >= gap && a[j-gap] > t) {
a[j] = a[j - gap]
j = j - gap
}
a[j] = t
}
}
}
}
 
var as = [ [4, 65, 2, -31, 0, 99, 2, 83, 782, 1], [7, 5, 2, 6, 1, 4, 2, 6, 3] ]
for (a in as) {
System.print("Before: %(a)")
shellSort.call(a)
System.print("After : %(a)")
System.print()
}</lang>
 
{{out}}
<pre>
Before: [4, 65, 2, -31, 0, 99, 2, 83, 782, 1]
After : [-31, 0, 1, 2, 2, 4, 65, 83, 99, 782]
 
Before: [7, 5, 2, 6, 1, 4, 2, 6, 3]
After : [1, 2, 2, 3, 4, 5, 6, 6, 7]
</pre>
 
=={{header|XPL0}}==
9,485

edits