-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbinsort.py
More file actions
35 lines (26 loc) · 780 Bytes
/
binsort.py
File metadata and controls
35 lines (26 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from random import randint
def findMax(arr): # for finding the biggest element in the list
m = 0
for i in range (0,len(arr)):
if m < arr[i]:
m = arr[i]
return m
def binsort(array):
n = len(array) # the length of the lsit
tmp = []
m = findMax(array)
for j in range(0,m+1): # filling up the auxiliary array with zeros
tmp.append(0)
for i in range(0,n): # counting each element in the input array
tmp[array[i]] += 1
q = 0
for i in range(0,m+1): # rewriting the input array
for j in range(0,tmp[i]):
array[q] = i
q += 1
return array # returning the sorted array
a = []
for i in range(0,100):
a.append(randint(0,1000000))
print a
print binsort(a)