Created
July 4, 2019 16:50
-
-
Save tuvo1106/7dba7f86367b6832b08a548fc7a11435 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def countsort(l:list): | |
arr = l[::] | |
k = 0 | |
new_list = (max(arr) + 1) * [0] | |
for j in arr: | |
new_list[j] += 1 | |
for i in range(max(arr) + 1): | |
if i != 0: | |
new_list[i] += new_list[i - 1] | |
while new_list[i] != k: | |
arr[k] = i; | |
k += 1 | |
return arr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment