Jump to content

Sorting algorithms/Gnome sort: Difference between revisions

Add Nimrod
(→‎version 1: reverted back to non-leading blank strings, removes STYLE from PRE html tag.)
(Add Nimrod)
Line 1,094:
[1, 2, 3, 3, 3, 4, 5, 6]
</pre>
 
=={{header|Nimrod}}==
<lang nimrod>proc gnomeSort[T](a: var openarray[T]) =
var
n = a.len
i = 1
j = 2
while i < n:
if a[i-1] > a[i]:
swap a[i-1], a[i]
dec i
if i > 0: continue
i = j
inc j
 
var a = @[4, 65, 2, -31, 0, 99, 2, 83, 782]
gnomeSort a
echo a</lang>
Output:
<pre>@[-31, 0, 2, 2, 4, 65, 83, 99, 782]</pre>
 
=={{header|Objeck}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.