Question: This is my code so farr. I need to fix my code because I am not allowed to use built in function. Help please.def count
This is my code so farr. I need to fix my code because I am not allowed to use built in function. Help please.def countsortarr: StaticArray StaticArray:
This function use the count sort algorithm that receives a StaticArray
and returns a new StaticArray with the same content sorted in nonascending
order.
# # Find the range of the input values
minimumvalue maximumvalue arr
for i in rangearrlength:
val arr.geti
if val minimumvalue:
minimumvalue val
if val maximumvalue:
maximumvalue val
# Initialize the count array
# countrange maximumvalue minimumvalue
# countarray countrange
countarray maximumvalue minimumvalue
# Fill the count array
for i in rangearrlength:
countarrayarrgeti minimumvalue
# Initialize the sorted static array
sortedarray StaticArrayarrlength
# Populate the sorted static array in nonascending order
sortedindex
for val in rangemaximumvalue, minimumvalue :
count countarrayval minimumvalue
while count :
sortedarraysortedindex val
sortedindex
count
return sortedarray
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
