--[[
Counting Sort
Complexity: O(n + k)
@param {table} array
@param {number} k
@return {table}
]]
function countingSort(array, k)
local count = {}
local result = {}
for i = 1, k do
count[i] = 0
end
for i = 1, #array do
count[array[i]] = count[array[i]] + 1
end
for i = 2, k do
count[i] = count[i] + count[i - 1]
end
for i = #array, 1, -1 do
result[count[array[i]]] = array[i]
count[array[i]] = count[array[i]] - 1
end
return result
end
local array = {2, 5, 3, 0, 2, 3, 0, 3}
local result = countingSort(array, 5)
for i = 1, #result do
print(result[i])
end
No he is looking to show off his script and gain feedback for it
edit: in short the rules should be changed, because by the rules, this is allowed, so its like you can post these scripts in creations feedback but you can also post them in code review.