We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d3adf0a commit bd2666fCopy full SHA for bd2666f
Counting Sort/counting_sort.py
@@ -0,0 +1,20 @@
1
+def MaximumNumber(arr):
2
+ if len(arr) == 0: return 0
3
+ mx = arr[0]
4
+ for i in range(1, len(arr)):
5
+ if mx < arr[i]:
6
+ mx = arr[i]
7
+ return mx
8
+
9
+def CountingSort(arr):
10
+ tempNum = MaximumNumber(arr)
11
+ n = len(arr) if len(arr) > tempNum else tempNum + 1
12
+ tempArr = [0] * n
13
+ for i in range(len(arr)): tempArr[arr[i]]+= 1
14
+ j = 0
15
+ for i in range(n):
16
+ while tempArr[i] != 0:
17
+ arr[j] = i
18
+ tempArr[i]-= 1
19
+ j += 1
20
+ return arr
0 commit comments