MCPcopy Create free account
hub / github.com/geekcomputers/Python / counting_sort

Function counting_sort

Sorting Algorithms/Count sort.py:1–13  ·  view source on GitHub ↗
(array1, max_val)

Source from the content-addressed store, hash-verified

1def counting_sort(array1, max_val):
2 m = max_val + 1
3 count = [0] * m
4
5 for a in array1:
6 # count occurences
7 count[a] += 1
8 i = 0
9 for a in range(m):
10 for c in range(count[a]):
11 array1[i] = a
12 i += 1
13 return array1
14
15
16print(counting_sort([1, 2, 7, 3, 2, 1, 4, 2, 3, 2, 1], 7))

Callers 1

Count sort.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected