diff --git a/tp7/exo5.ml b/tp7/exo5.ml index 64af0a2..f05f711 100644 --- a/tp7/exo5.ml +++ b/tp7/exo5.ml @@ -2,3 +2,33 @@ type 'a lc = { mutable tete : 'a option; mutable suivant : 'a lc option };; + +let creer_lc () = { + tete=None; + suivant=None; +};; + +let rec taille_lc l = match l with + | { + tete = None; + suivant = None + } -> 0 + | {suivant = None; _} -> 1 + | {suivant = Some s; _} -> 1 + (taille_lc s) +;; + +let rec acces_lc l i = match l,i with + | {tete=Some t;_}, 0 -> t + | {suivant=Some s;_}, i when i>0 -> acces_lc s (i-1) + | _ -> invalid_arg "" +;; + +let rec inserer_lc l i x = match l,i with + | {suivant=s;_}, 0 -> + l.suivant <- Some { + tete=Some x; + suivant=s + } + | {suivant=Some s;_}, i -> + inserer_lc s (i-1) x + | _ -> invalid_arg ""