Add gnome sort

This commit is contained in:
joachimschmidt557 2019-05-02 13:21:11 +02:00
parent 8bb40d0f3b
commit 89c4a153f3

16
GnomeSort.nim Normal file
View file

@ -0,0 +1,16 @@
proc gnomeSort(list:var seq[int]) =
var
i = 0
while i < list.high:
if list[i] > list[i + 1]:
swap(list[i + 1], list[i])
if i > 0:
dec i
else:
inc i
when isMainModule:
var
seq1 = @[1, 3, 2, 56, 2, 1, 32, 45, 23, 41, 6, 47, 212, 32, 6, 98, 54, 457, 37, 4]
gnomeSort(seq1)
echo seq1