Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

# using the methods available in StaticArray class because we are not allowed to use the built - in methods in Python minVal = array.get

# using the methods available in StaticArray class because we are not allowed to use the built-in methods in Python
minVal = array.get(0)
maxVal = array.get(0)
arrayLength = array.length()
# Finding min and max values of the input array
for x in range(1, arrayLength):
temp = array.get(i)
# We must not use inbuilt min() and max() functions
if(maxVal < temp):
maxVal = temp
elif(minVal > temp):
minVal = temp
# Finding the range of values present in the array
rangeOfValues =(maxVal - minVal)+1
# count_arr stores the count of each value in the array
count_arr = StaticArray(rangeOfValues)
for i in range(rangeOfValues):
count_arr.set(i,0)
for i in range(arrayLength):
temp = array.get(i)
j = temp - minVal
count_arr.set(j, count_arr.get(j+1))
# sorted array to be returned
sortedStaticArray = StaticArray(arrayLength)
lastIndex = arrayLength -1
for i in range(rangeOfValues-1,-1,-1): # loop thrugh the array in the reverse order
while(count_arr.get(i)>0):
temp = i + minVal
sortedStaticArray.set(lastIndex, temp)
lastIndex -=1
count_arr.set(i,(count_arr.get(i)-1))
return sortedStaticArray

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Databases Concepts And Practice

Authors: Suzanne W Dietrich

1st Edition

1119827949, 9781119827948

More Books

Students also viewed these Databases questions

Question

What are the five basic steps in revenue recognition?

Answered: 1 week ago

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago