我必须编写一个程序,在输出中输入一个元组:非空列表的最小值和最大值以及最常出现的值.特别是:
min_max [1;0;-1;2;0;-4] ==> (-4; 2)
min_max: int list -> (int * int)
mode [-1;2;1;2;5;-1;5;5;2] ==> 2
mode: int list -> int
Run Code Online (Sandbox Code Playgroud)
这是我为max编写的代码(min几乎相等)但是如何使用这两个值作为输出接收元组?
let rec max_list xs =
match xs with
| [] -> failwith "xs" "Empty list"
| [x] -> x
| x1::x2::xs' -> max_list((max2 x1 x2)::xs');;
Run Code Online (Sandbox Code Playgroud) f# ×1