Sorting algorithms/Gnome sort: Difference between revisions
m
→{{header|RPL}}: improved code
(Added PL/M) |
m (→{{header|RPL}}: improved code) |
||
(3 intermediate revisions by 3 users not shown) | |||
Line 446:
{{works with|ALGOL 68G|Any - tested with release mk15-0.8b.fc9.i386}}
{{works with|ELLA ALGOL 68|Any (with appropriate job cards
<syntaxhighlight lang="algol68">MODE SORTSTRUCT = INT;
Line 4,089:
j = j + 1 ok ok end
</syntaxhighlight>
=={{header|RPL}}==
{{works with|RPL|HP-49C}}
« DUP SIZE 1 → s h
« 2
'''WHILE''' h s < '''REPEAT'''
'''IF''' OVER h DUP 1 + SUB EVAL ≤ '''THEN'''
'h' ▶ 1 +
'''ELSE'''
SWAP h DUP2 DUP 1 + SUB REVLIST REPL SWAP
'''IF''' 'h' DECR NOT '''THEN''' 'h' ▶ 1 + '''END'''
'''END'''
'''END''' DROP
» » '<span style="color:blue">GNOMESORT</span>' STO
{ 7 6 5 9 8 4 3 1 2 0 } <span style="color:blue">GNOMESORT</span>
{{out}}
<pre>
1: { 0 1 2 3 4 5 6 7 8 9 }
</pre>
This implementation of gnome sort is 30 times slower than the <code>SORT</code> built-in function on a HP-50g.
=={{header|Ruby}}==
Line 4,523 ⟶ 4,544:
=={{header|Wren}}==
<syntaxhighlight lang="
var size = a.count
var i = 1
Line 4,544 ⟶ 4,565:
}
var
for (asc in [true, false]) {
System.print("Sorting in %(asc ? "ascending" : "descending") order:\n")
for (a in
var b = (asc) ? a : a.toList
System.print("Before: %(b)")
|