vault backup: 2023-10-26 20:56:10

This commit is contained in:
Louis Gallet 2023-10-26 20:56:11 +02:00
parent 7b5e822d93
commit 998022df1d
Signed by: lgallet
SSH Key Fingerprint: SHA256:qnW7pk4EoMRR0UftZLZQKSMUImbEFsiruLC7jbCHJAY

View File

@ -2,10 +2,28 @@
let rec insert_post x f = function let rec insert_post x f = function
| [] -> Failwith "x cannot be inserted" | [] -> Failwith "x cannot be inserted"
| e::t -> if f e then e::x::t else y::insert_post x f t;; | 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 pos_max lst = let x = 1 in match lst with let rec pos_max lst = let x = 1 in match lst with
| [] -> invalid_arg "post_max: empty list" | [] -> invalid_arg "post_max: empty list"
| e::[] -> e | e::[] -> x
| e1::e2::t -> if e2 > e1 then | e1::e2::t ->
x = x + 1; if e2 > e1 then
e2::pos_max else e1::t;; 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