Anonymous user
Sorting algorithms/Gnome sort: Difference between revisions
Added untested BASIC trans of C
(Added untested Java trans from C) |
(Added untested BASIC trans of C) |
||
Line 22:
'''Task''': implement the Gnome sort in your language to sort an array (or list) of numbers.
=={{header|BASIC}}==
{{works with|QuickBasic|4.5}}
{{trans|C}}
<lang qbasic>dim a(0 to n-1) as integer
'...more code...
sort:
i = 1
j = 2
while(i < ubound(a) - lbound(a))
if a(i-1) <= a(i) then
i = j
j = j + 1
else
swap a(i-1), a(i)
i = i - 1
if i = 0 then
i = j
j = j + 1
end if
end if
wend</lang>
=={{header|C}}==
|