Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Fix sorts/radix_sort #338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 20 additions & 22 deletions sorts/radix_sort.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
def radixsort(lst):
RADIX = 10
maxLength = False
tmp , placement = -1, 1
RADIX = 10
placement = 1

while not maxLength:
maxLength = True
# declare and initialize buckets
buckets = [list() for _ in range( RADIX )]
# get the maximum number
max_digit = max(lst)

# split lst between lists
for i in lst:
tmp = int((i / placement) % RADIX)
buckets[tmp].append(i)
while placement < max_digit:
# declare and initialize buckets
buckets = [list() for _ in range( RADIX )]

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

# empty lists into lst array
a = 0
for b in range( RADIX ):
buck = buckets[b]
for i in buck:
lst[a] = i
a += 1
# 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
# move to next
placement *= RADIX