75 lines
1.8 KiB
OCaml
75 lines
1.8 KiB
OCaml
let n = 26;;
|
|
let lettre i = match i with
|
|
| 0 -> print_string " "
|
|
| -1 -> print_endline ""
|
|
| i -> print_string (String.make 1 (Char.chr (96+i)));;
|
|
|
|
type mot = int list;;
|
|
|
|
let imprimer motDG =
|
|
let rec aux mot = match mot with
|
|
| [] -> ()
|
|
| e::s -> aux s;lettre e in
|
|
aux motDG;
|
|
lettre (-1);;
|
|
|
|
let inverseDe motDG =
|
|
let rec aux mot motGD= match mot with
|
|
| [] -> motGD
|
|
| e::s -> aux s (e::motGD) in
|
|
aux motDG [];;
|
|
|
|
type dictTab = VideT | NoeudT of dictTab array;;
|
|
|
|
let dicoVide = VideT;;
|
|
let dicoMotVide () = let out = Array.make (n+1) VideT in out.(0) <- NoeudT(Array.make (n+1) VideT); NoeudT(out);;
|
|
|
|
let imprimerDictTab dt =
|
|
let rec aux dt prefixe = let NoeudT(arr) = dt in
|
|
for i=1 to n do
|
|
if arr.(i)!=VideT
|
|
then aux arr.(i) (i::prefixe)
|
|
done;
|
|
if arr.(0)!=VideT
|
|
then imprimer prefixe (* Faut ptet inverser *)
|
|
in match dt with
|
|
| VideT -> ()
|
|
| _ -> aux dt [];;
|
|
|
|
let rec estDansDictTab motGD dt = match dt with
|
|
| VideT -> false
|
|
| NoeudT(arr) ->
|
|
match motGD with
|
|
| [] -> arr.(0)!=VideT (* Le caractère fin de mot est dans le dico *)
|
|
| e::s -> estDansDictTab s arr.(e);;
|
|
|
|
let rec ajoutADictTab mot dt = match mot with
|
|
| [] -> dicoMotVide ()
|
|
| e::s ->
|
|
match dt with
|
|
| VideT -> let feuille = (Array.make (n+1) VideT) in
|
|
feuille.(e) <- ajoutADictTab s VideT;NoeudT(feuille)
|
|
| NoeudT(arr) ->
|
|
arr.(e) <- ajoutADictTab s arr.(e);NoeudT(arr);;
|
|
|
|
let motDG = [1;2;3];;
|
|
|
|
|
|
|
|
|
|
imprimer motDG;;
|
|
inverseDe motDG;;
|
|
|
|
let monpredico = dicoMotVide ();;
|
|
|
|
let NoeudT(x) = monpredico in
|
|
x.(5) <- dicoMotVide ();
|
|
x.(8) <- dicoMotVide ();
|
|
x.(21) <- dicoMotVide ();
|
|
let NoeudT(arr) = x.(5) in
|
|
arr.(8) <- dicoMotVide ();;
|
|
|
|
imprimerDictTab monpredico;;
|
|
estDansDictTab [5;7] monpredico;;
|
|
let monpredico2 = ajoutADictTab [5;9;9] monpredico;;
|
|
imprimerDictTab monpredico2;; |