tp7 exo5
This commit is contained in:
parent
b6f6148333
commit
e5044b4fe2
30
tp7/exo5.ml
30
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 ""
|
||||
|
||||
Loading…
Reference in New Issue
Block a user