datatype arbre = noeud of bool * (string * arbre) list fun fst (x,y) = x fun snd (x,y) = y fun println s = print (s ^ "\n") fun existe_car (l1)(car , nil) = (l1,nil) | existe_car (l1)(car,x::l2) = (if car = fst(x) then (l1,x::l2) else existe_car(l1 @ [x]) (car,l2) ) fun creer_branche (l) = (if length(l) = 0 then noeud(true,nil) else noeud(false,[(hd(l),creer_branche (tl(l)))]) ) fun cumul_mots (lres) (lmot) (noeud(b,nil)) = (if b then lres @ [ implode(lmot) ] else lres ) | cumul_mots (lres) (lmot) (noeud(b,x::l)) = (if b then cumul_mots (lres @ [ implode(lmot) ]) (lmot @ [fst(x)])(snd(x)) else cumul_mots (lres) (lmot @ [fst(x)]) (snd(x)) ) @ cumul_mots (nil) (lmot) (noeud(false,l)) (* fun creer_arbre l = fold (ajouter) l (noeud(false, nil)) *) fun liste_mots a = cumul_mots nil nil (a) fun nombre_mots a = length(liste_mots a) (* fun afficher_ratio a = println ( "Ratio de stockage : " ^ makestring(floor(ratio(a))) ^ "%" ) *) fun afficher a = app println (liste_mots (a)) (* fun afficher_par_prefixe (m,a) = app println (liste_par_prefixe (m,a)) *) (* fun supprimer_mots (l,a) = fold ... un peu comme creer_arbre *)