Skip to content

Commit

Permalink
Create radix_sort.py
Browse files Browse the repository at this point in the history
  • Loading branch information
theycallmemac authored Feb 25, 2017
1 parent 94a3099 commit e823c55
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions sorts/radix_sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
def radixsort(lst):
RADIX = 10
maxLength = False
tmp , placement = -1, 1

while not maxLength:
maxLength = True
# declare and initialize buckets
buckets = [list() for _ in range( RADIX )]

# split lst between lists
for i in lst:
tmp = i / placement
buckets[tmp % RADIX].append( i )
if maxLength and tmp > 0:
maxLength = False

# empty lists into lst array
a = 0
for b in range( RADIX ):
buck = buckets[b]
for i in buck:
lst[a] = i
a += 1

# move to next
placement *= RADIX

0 comments on commit e823c55

Please sign in to comment.