Question
3. Using the radix sort algorithm, implement the code below IN PYTHON and add this to the code: generate a list of 100 random numbers
3. Using the radix sort algorithm, implement the code below IN PYTHON and add this to the code: generate a list of 100 random numbers from 1000 possible values. Print the list. Run the algorithm and make sure you show the list after each pass (in other words, if there are, say, three digits max in each number, then your output should show the original list, the list after the units digit is processed, the list after the tens digit is processed, and then the final sorted list.) Commentwill the code run successfully if all of the digits are not the same length? In other words, if I have values of, say, 76 and 124, do I need to make the 76 be represented as 076 or will the code handle it correctly?
Here is the radix sort code:
from llistqueue import Queue
from array import Array
def radixSort( intList, numDigits):
binArray = Array (10)
for k in range(10):
binArray[k]= Queue()
column = 1
for d in range(numDigits):
for key in intList:
digit = (key//column)%10
binArray[digit].enqueue(key)
i = 0
for bin in binArray:
while not bin.isEmpty():
intList[i] = bin.dequeue()
i += 1
column *=10
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started