Skip to content

Instantly share code, notes, and snippets.

@hoffoo
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hoffoo/b420d1ecc60ad6ec44e5 to your computer and use it in GitHub Desktop.
Save hoffoo/b420d1ecc60ad6ec44e5 to your computer and use it in GitHub Desktop.
local array = {1,2,0,0,3,1,2}
function swap(a, b, table)
if table[a] == nil or table[b] == nil then
return false
end
if table[a] > table[b] then
table[a], table[b] = table[b], table[a]
return true
end
return false
end
function bubblesort(array)
for i=1,table.maxn(array) do
local ci = i
::redo::
if swap(ci, ci+1, array) then
ci = ci - 1
goto redo
end
end
end
bubblesort(array)
for k, v in pairs(array) do
print(k, " ", v)
end
@qaisjp
Copy link

qaisjp commented Mar 9, 2015

Interesting implementation... are goto's more efficient than recursion?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment