forked from codehouseindia/Python-Programs
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCountingSort.py
More file actions
Latest commit
20 lines (18 loc) · 463 Bytes
/
Copy pathCountingSort.py
File metadata and controls
20 lines (18 loc) · 463 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#DarkSouL
defcountSort(arr):
output= [0foriinrange(256)]
count= [0foriinrange(256)]
ans= [""for_inarr]
foriinarr:
count[ord(i)] +=1
foriinrange(256):
count[i] +=count[i-1]
foriinrange(len(arr)):
output[count[ord(arr[i])]-1] =arr[i]
count[ord(arr[i])] -=1
foriinrange(len(arr)):
ans[i] =output[i]
returnans
arr="ExpectoPatronum"
ans=countSort(arr)
print"Sorted character array is %s"%("".join(ans))