Answered step by step
Verified Expert Solution
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 builtin methods in Python
minVal array.get
maxVal array.get
arrayLength array.length
# Finding min and max values of the input array
for x in range arrayLength:
temp array.geti
# We must not use inbuilt min and max functions
ifmaxVal temp:
maxVal temp
elifminVal temp:
minVal temp
# Finding the range of values present in the array
rangeOfValues maxVal minVal
# countarr stores the count of each value in the array
countarr StaticArrayrangeOfValues
for i in rangerangeOfValues:
countarr.seti
for i in rangearrayLength:
temp array.geti
j temp minVal
countarr.setj countarr.getj
# sorted array to be returned
sortedStaticArray StaticArrayarrayLength
lastIndex arrayLength
for i in rangerangeOfValues: # loop thrugh the array in the reverse order
whilecountarr.geti:
temp i minVal
sortedStaticArray.setlastIndex temp
lastIndex
countarr.seticountarr.geti
return sortedStaticArray
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