Analyse d'ajouter un élément à droite. 1- Profile : ajd : int list * int -> int list 2- Sémantique : ajd(l,x) = la liste l plus l'élément x ajouté à droite. ajd([2;3;4],9) = [2;3;4;9] 3 - Equations de récurrences : ajd([],x) = [x] ajd(y::fin,x) = y::(ajd(fin,x)) 4 - Implantation en Ocaml let rec ajd (l:int list) (x:int) = match l with | [ ] -> [x] |y::fin -> y::(ajd fin x);; Inversion d'une liste 1- Profil : inversion : int list -> int list 2- Sémantique : inversion(l) = la liste qui contient les mêmes éléments que l mais en ordre inverse. inversion([1;2;3;4]) =[4;3;2;1] x = 1 fin =[2;3;4] invesion(fin) = [4;3;2] 3- Equations de récurrences : inversion([]) = [] inversion(x::fin) = ajd (inversion(fin),x) 4- Implantation : let rec inversion (l:int list) = match l with [] -> [] | x::fin -> ajd (inversion fin) x;; Concaténation de deux listes 1- Profil : concat int list * int list -> int list 2- Sémantique : concat l1 l2 = la liste qui contient tous les éléments de l1 suivis des éléments de l2 dans l'ordre. concat [2;4;6;8] [1;3;5;7] = [2;4;6;8;1;3;5;7] x=2 fin=[4;6;8] conca(fin,l2)=[4;6;8;1;3;5;7] 3- Equations de récurrence concat ([],l2) = l2 concat (x::fin,l2) = x::concat(fin,l2) 4- Implantation let rec concat (l1:int list) (l2:int list) : int list = match l1 with [] -> l2 | x::fin -> x::(concat fin l2);; Suppression de n occurrences de e dans l. 1- Profil : supp_occ int list*int*int -> int list 2- Sémantique : supp_occ(l,e,n) = la liste l dans laquelle on supprime les n premières occurences de e (s'il y en a suffisamment). supp_occ([4;7;8;12;45;12;43;90;12],12,2)=[4;7;8;45;43;90;12] supp_occ([4;7;8;12;45;12;43;90;12],98,7)=[4;7;8;12;45;12;43;90;12] supp_occ([4;7;8;12;45;12;43;90;12],12,5)=[4;7;8;45;43;90] x= 4 fin=[7;8;12;45;12;43;90;12] n+1 = 5 3- Equations de récurrence : supp_occ ([],e,0) = [] supp_occ (x::fin,e,0) = x::fin supp_occ ([],e,n+1) = [] supp_occ (x::fin,e,n+1) = if x=e then supp_occ (fin,e,n) else x::(supp_occ(fin,e,n+1)) 4- Implantation let rec supp_occ (l:int list) (e:int) (n:int) : int list = match (l,n) with ([],_) -> [] |(x::fin,_) -> if (n=0) then x::fin else (if x=e then (supp_occ fin e (n-1)) else x::(supp_occ fin e n));;