Question: # 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
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
