Skip to content

Instantly share code, notes, and snippets.

@ssteuteville
Created September 14, 2016 03:28
Show Gist options
  • Save ssteuteville/04f11c0008de530f1db5a294a6a38b06 to your computer and use it in GitHub Desktop.
Save ssteuteville/04f11c0008de530f1db5a294a6a38b06 to your computer and use it in GitHub Desktop.
count sort
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