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 count_sort(arr: StaticArray)-> StaticArray:
"""
This function use the count sort algorithm that receives a StaticArray
and returns a new StaticArray with the same content sorted in non-ascending
order.
"""
# # Find the range of the input values
minimum_value = maximum_value = arr[0]
for i in range(arr.length()):
val = arr.get(i)
if val < minimum_value:
minimum_value = val
if val > maximum_value:
maximum_value = val
# Initialize the count array
# count_range = maximum_value - minimum_value +1
# count_array =[0]* count_range
count_array =[0]*(maximum_value - minimum_value +1)
# Fill the count array
for i in range(arr.length()):
count_array[arr.get(i)- minimum_value]+=1
# Initialize the sorted static array
sorted_array = StaticArray(arr.length())
# Populate the sorted static array in non-ascending order
sorted_index =0
for val in range(maximum_value, minimum_value -1,-1):
count = count_array[val - minimum_value]
while count >0:
sorted_array[sorted_index]= val
sorted_index +=1
count -=1
return sorted_array

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!