Add gnome sort
This commit is contained in:
parent
8bb40d0f3b
commit
89c4a153f3
1 changed files with 16 additions and 0 deletions
16
GnomeSort.nim
Normal file
16
GnomeSort.nim
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue