Created
September 14, 2016 03:28
-
-
Save ssteuteville/04f11c0008de530f1db5a294a6a38b06 to your computer and use it in GitHub Desktop.
count sort
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
def counting_sort(l, upper_bound): | |
counts = [0] * (upper_bound + 1) | |
ret = [] | |
# count how many times each number occurs | |
for i in l: | |
counts[i] += 1 | |
# fill in ret | |
for i, count in enumerate(counts): | |
for _ in range(count): | |
ret.append(i) | |
return ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment