Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
|
|
@ -0,0 +1,28 @@
|
|||
local function cocktail_sort(a)
|
||||
local last = #a
|
||||
while true do
|
||||
local swapped = false
|
||||
for i = 1, last - 1 do
|
||||
if a[i] > a[i + 1] then
|
||||
a[i], a[i + 1] = a[i + 1], a[i]
|
||||
swapped = true
|
||||
end
|
||||
end
|
||||
if !swapped then return end
|
||||
swapped = false
|
||||
if last >= 1 then
|
||||
for i = last - 1, 1, -1 do
|
||||
if a[i] > a[i + 1] then
|
||||
a[i], a[i + 1] = a[i + 1], a[i]
|
||||
swapped = true
|
||||
end
|
||||
end
|
||||
end
|
||||
if !swapped then return end
|
||||
end
|
||||
end
|
||||
|
||||
local a = {170, 45, 75, -90, -802, 24, 2, 66}
|
||||
print($"Before: \{{a:concat(", ")}}")
|
||||
cocktail_sort(a)
|
||||
print($"After : \{{a:concat(", ")}}")
|
||||
Loading…
Add table
Add a link
Reference in a new issue