Skip to content

Instantly share code, notes, and snippets.

@Polkm
Created May 24, 2015 19:46
Show Gist options
  • Save Polkm/9ae23eb774cbda93afb1 to your computer and use it in GitHub Desktop.
Save Polkm/9ae23eb774cbda93afb1 to your computer and use it in GitHub Desktop.
local function deafultSort(a, b) return a > b end
function table.insertSort(tbl, func)
func = func or deafultSort
local len = #tbl
for j = 2, len do
local key, i = tbl[j], j - 1
while i > 0 and not func(tbl[i], key) do
tbl[i + 1] = tbl[i]
i = i - 1
end
tbl[i + 1] = key
end
return tbl
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment