Answer
procedure getvalues ($a_1, a_2, a_3:$ three integers)
bubblesort($a_1, a_2, a_3$)
{Bubblesort was defined in the chapter - Any sorting algorithm would do}
min $:= a_1$
max $:= a_3$
median $:= a_2$
mean $:= \frac{a_1+a_2+a_3}{3}$
return {max, median, mean, min}
{We return a set consisting of the four values that were asked for}
Work Step by Step
This algorithm attempts to calculate the minimum, maximum, median and mean for three integers.
By first sorting the array, we cut the amount of work we have to do substantially. By sorting the array, we know that the minimum value is the first; the median is the second (middle value), and the maximum is the last.
To calculate the mean, we just sum up all the values and divide by 3.
We return the four values as a set.