Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @staticmethod
- def radix_sort(a):
- """
- -------------------------------------------------------
- Performs a base 10 radix sort.
- Use: Sorts.radix_sort(a)
- -------------------------------------------------------
- Preconditions:
- a - an array of base 10 integers (list)
- Postconditions:
- Contents of a are sorted.
- -------------------------------------------------------
- """
- RADIX = 10
- maxLength = False
- tmp , placement = -1, 1
- while not maxLength:
- maxLength = True
- # declare and initialize buckets
- buckets = [list() for _ in range(RADIX)]
- # split a between lists
- for i in a:
- tmp = int(i / placement)
- buckets[tmp % RADIX].append(i)
- if maxLength and tmp > 0:
- maxLength = False
- x = 0
- for b in range(RADIX):
- bucket = buckets[b]
- for i in bucket:
- a[x] = i
- x += 1
- # move to next digit
- placement *= RADIX
- return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement