vault backup: 2023-10-26 20:56:10
This commit is contained in:
parent
7b5e822d93
commit
998022df1d
26
Code CAML.md
26
Code CAML.md
@ -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 ->
|
||||||
|
if e2 > e1 then
|
||||||
|
begin
|
||||||
x = x + 1;
|
x = x + 1;
|
||||||
e2::pos_max else e1::t;;
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user