epicours/Code CAML.md

324 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;;

let pos_max lst = let x = 1 in match lst with
	| [] -> invalid_arg "post_max: empty list"
	| e::[] -> e
	| e1::e2::t -> if e2 > e1 then
		x = x + 1; 
		e2::pos_max  else e1::t;;