Skip to content

Commit

Permalink
Update radix_sort.py
Browse files Browse the repository at this point in the history
added a random array to test the sort
  • Loading branch information
MrWeast committed Dec 1, 2023
1 parent dedbe88 commit 9f03e18
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/python/radix_sort.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import random

def radix_sort(arr):
# Find the maximum number to know the number of digits
max_num = max(arr)
Expand Down Expand Up @@ -33,11 +35,23 @@ def counting_sort(arr, exp):


def main():
print("Fixed Testing Array")
arr = [170, 2, 45, 75, 75, 90, 802, 24, 2, 66]
print("Unsorted array:", arr)
radix_sort(arr)
print("Sorted array:", arr)

print("Random Testing Array")
arr = []
for i in range(0,10):
arr.append(random.randint(0,20))
print("Unsorted array:", arr)
radix_sort(arr)
print("Sorted array:", arr)





if __name__ == "__main__":
main()

0 comments on commit 9f03e18

Please sign in to comment.