Skip to content

Commit 9f03e18

Browse files
committed
Update radix_sort.py
added a random array to test the sort
1 parent dedbe88 commit 9f03e18

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/python/radix_sort.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import random
2+
13
def radix_sort(arr):
24
# Find the maximum number to know the number of digits
35
max_num = max(arr)
@@ -33,11 +35,23 @@ def counting_sort(arr, exp):
3335

3436

3537
def main():
38+
print("Fixed Testing Array")
3639
arr = [170, 2, 45, 75, 75, 90, 802, 24, 2, 66]
3740
print("Unsorted array:", arr)
3841
radix_sort(arr)
3942
print("Sorted array:", arr)
4043

44+
print("Random Testing Array")
45+
arr = []
46+
for i in range(0,10):
47+
arr.append(random.randint(0,20))
48+
print("Unsorted array:", arr)
49+
radix_sort(arr)
50+
print("Sorted array:", arr)
51+
52+
53+
54+
4155

4256
if __name__ == "__main__":
4357
main()

0 commit comments

Comments
 (0)