Sorting algorithms/Shell sort: Difference between revisions

Added Easylang
(→‎{{header|Vlang}}: Rename "Vlang" in "V (Vlang)")
(Added Easylang)
 
(One intermediate revision by one other user not shown)
Line 1,764:
}
}</syntaxhighlight>
 
=={{header|EasyLang}}==
{{trans|Lua}}
<syntaxhighlight>
proc shellsort . a[] .
inc = len a[] div 2
while inc > 0
for i = inc to len a[]
tmp = a[i]
j = i
while j > inc and a[j - inc] > tmp
a[j] = a[j - inc]
j = j - inc
.
a[j] = tmp
.
inc = floor (0.5 + inc / 2.2)
.
.
a[] = [ -12 3 0 4 7 4 8 -5 9 ]
shellsort a[]
print a[]
</syntaxhighlight>
{{out}}
<pre>
[ -12 -5 0 3 4 4 7 8 9 ]
</pre>
 
=={{header|Eiffel}}==
Line 3,725 ⟶ 3,752:
=={{header|Wren}}==
Based on the Wikipedia article pseudo-code.
<syntaxhighlight lang="ecmascriptwren">var shellSort = Fn.new { |a|
var n = a.count
var gaps = [701, 301, 132, 57, 23, 10, 4, 1]
Line 3,743 ⟶ 3,770:
}
 
var asarray = [ [4, 65, 2, -31, 0, 99, 2, 83, 782, 1], [7, 5, 2, 6, 1, 4, 2, 6, 3] ]
for (a in asarray) {
System.print("Before: %(a)")
shellSort.call(a)
Line 3,762 ⟶ 3,789:
Alternatively we can just call a library method.
{{libheader|Wren-sort}}
<syntaxhighlight lang="ecmascriptwren">import "./sort" for Sort
 
var asarray = [ [4, 65, 2, -31, 0, 99, 2, 83, 782, 1], [7, 5, 2, 6, 1, 4, 2, 6, 3] ]
for (a in asarray) {
System.print("Before: %(a)")
Sort.shell(a)
2,083

edits