type corde = F of string | N of int * corde * corde;; let exemple = N (18, F "Le", N (16, N (5, F "Peti", F "t"), N (11, N (8, F "ChatEs", F "tM"), F "ort")));; let rec transforme = function | [r] -> r | lst -> let rec zipper = function | [] -> failwith "impossible" | a::b::t when t=[] || length a <= length (List.hd t) -> t, concat a b | h::t -> match zipper t with | rst, (N _ as r) when length r <= length h -> h::r::rst, F "" | rst, r -> h::rst, r in let rst, r = zipper lst in transforme (if r = F "" then rst else r::rst)