This commit is contained in:
Arkitu 2026-01-15 09:13:07 +01:00
parent b6f6148333
commit e5044b4fe2

View File

@ -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 ""