Last active
March 1, 2020 22:22
-
-
Save zambony/12d1cd8569e28e5d23322b75a0cb62e6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Convenience function to explode some text | |
local function explode(str, separator) | |
local out = {} | |
for w in str:gmatch("([^" .. separator .. "]+)") do out[#out + 1] = w end | |
return out | |
end | |
function table.swap(t, a, b) | |
t[a], t[b] = t[b], t[a] | |
end | |
local defaultComp = function(a, b) return a > b end | |
function table.insertionsort(t, comp) | |
comp = comp or defaultComp | |
for i = 2, #t do | |
local j = i | |
while (j > 1 and comp(t[j - 1], t[j])) do | |
table.swap(t, j, j - 1) | |
j = j - 1 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment