--[[
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
This should go in code review.
I’m just saying it needs to go in code review, its in the wrong category.
For whoms benefit are they doing so?
Hello @xDeltaXen! This should go to #help-and-feedback:code-review
Pls read the following rules below
it says scripts are allowed
char limit
but isn’t this mainly more about code review?
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.
ok
understand now
I need to type more to post this because of character limit