Sorting algorithms/Cocktail sort: Difference between revisions

Updated to work with current version of Nim (1.4).
(→‎{{header|R}}: Used a cool R trick and tried to follow pseudo-code more closely. Also added more outputs.)
(Updated to work with current version of Nim (1.4).)
Line 2,630:
 
=={{header|Nim}}==
<lang nim>template trySwap(): stmt {.immediate.}untyped =
if a[i] < a[i-1]:
swap a[i], a[i-1]
Line 2,640:
while not t:
t = true
for i in 1 .. < l: trySwap
if t: break
for i in countdown(l-1, 1): trySwap
Anonymous user