670 B
670 B
let rec insert_post x f = function
| [] -> Failwith "x cannot be inserted"
| e::t -> if f e then e::x::t else y::insert_post x f t;;
val insert_post: 'a -> ('a -> bool) -> 'a list -> 'a list = <fun>
let rec pos_max lst = let x = 1 in match lst with
| [] -> invalid_arg "post_max: empty list"
| e::[] -> x
| e1::e2::t ->
if e2 > e1 then
begin
x = x + 1;
e2::pos_max t;
end;
else
e1::pos_max t;;
let pos_max lst =
if lst = [] then
failwith "pos_max: empty list"
else
let rec pmr mval mpos cpos = function
| [] -> mpos
| e::t ->
if e > mval then
pmr e cpos (cpos + 1) t
else
pmr mval mpos (cpos + 1) t