I need to make a program that displays the two maximum numbers in a list using Oz programming language. I have the code for printing the maximum number in a list, but I need the two biggest numbers. Here is what I have so far:
fun {Max L1}
case L1
of nil then 0
[] X|Xr then
if X>{Max Xr} then X
else {Max Xr}
end
end
end
{Browse {Max [1 2 3 4 5 6 7 8 9]}}
This will display the biggest number in the list, but only one and I need the two biggest numbers to display. What do I need to do?
There are many ways in Mozart-Oz to solve that problem. This is one possible solution which is extended to a list of size (length) N; however, only works for possitive numbers.
Notice the behavior of MaxN, when N is greater than the length of the list of numbers L1, the browser displays a list of length L1 with the first N biggest numbers. Negative numbers are replaced by zero. I hope this is still useful.