Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (* Les Listes *)
- (* FONCTION estSingleton *)
- let estSingleton l =
- match l with
- |[]->false
- |_::[]->true
- |_::_->false
- ;;
- (* TEST DE estSingleton *)
- let test_estSingleton =
- (estSingleton (1::[]) = true) &&
- (estSingleton [] = false) &&
- (estSingleton (1::2::[]) = false)
- ;;
- (* FONCTION deuxiemeElement *)
- let deuxiemeElement l =
- match l with
- |[]-> failwith "liste trop courte"
- |_::[]-> failwith "liste trop courte"
- |_::h::_-> h
- ;;
- (* TEST DE deuxiemeElement *)
- let test_deuxiemeElement =
- deuxiemeElement (1::2::[]) = 2
- ;;
- (* FOCNTION mult5 *)
- let rec mult5 l =
- match l with
- |[]->0
- |h::t-> if h mod 5 = 0
- then 1 + mult5 t
- else mult5 t
- ;;
- (* TEST DE mult5 *)
- let test_mult5 =
- mult5 (2::3::10::4::2::8::5::[]) = 2
- ;;
- (* FONCTION addLast *)
- let rec addLast l n =
- match l with
- |[]->n::[]
- |h::t->h::(addLast t n)
- ;;
- (* TEST DE addLast *)
- let test_addLast =
- addLast (1::2::3::4::[]) 5 = (1::2::3::4::5::[])
- ;;
- (* FOCNTION remLast *)
- let rec remLast l =
- match l with
- |[]->[]
- |h::t->if t = []
- then
- []
- else
- h::(remLast t)
- ;;
- (* TEST DE remLast *)
- let test_remLast =
- remLast (1::2::3::4::5::[]) = (1::2::3::4::[])
- ;;
- (* FONCTION croissante *)
- let rec croissante l =
- match l with
- |[]-> true
- |h::[]-> true
- |h1::h2::[]-> h1<h2
- |h1::h2::t-> h1<h2 && croissante t
- ;;
- (* TEST DE croissante *)
- let test_croissante =
- croissante (1::2::3::4::5::6::7::8::9::10::[])
- ;;
- (* FONCTION membre *)
- let rec membre x l =
- match l with
- |[]-> false
- |h::t-> h=x || membre x t
- ;;
- (* TEST DE membre *)
- let test_membre =
- membre 3 (1::2::3::4::[])
- ;;
- (* FOCNTION cherche_i*)
- let rec cherche_i i l =
- match l with
- |[]-> failwith "liste trop courte"
- |h::t-> if i=0
- then
- h
- else
- cherche_i (i-1) t
- ;;
- (* TEST DE cherche_i *)
- let test_cherche_i =
- cherche_i 3 (1::2::3::4::5::6::7::8::9::10::[]) = 4
- ;;
- (* FONCTION insert *)
- let rec insert x i l =
- match l with
- |[]-> if i = 0
- then
- x::[]
- else
- failwith "liste trop courte"
- |h::t-> if i=0
- then
- x::l
- else
- h::(insert x (i-1) t)
- ;;
- (* TEST DE insert *)
- let test_insert =
- insert 1 1 (3::3::3::3::3::[]) = (3::1::3::3::3::3::[])
- ;;
- (* FONCTION supprime_i *)
- let rec supprime_i i l =
- match l with
- |[]-> failwith "liste trop courte"
- |h::t-> if i=0
- then
- t
- else
- h::(supprime_i (i-1) t)
- ;;
- (* TEST DE supprime_i *)
- let test_supprime_i =
- supprime_i 2 (1::2::3::4::5::[]) = (1::2::4::5::[]);;
- ;;
- (* FONCTION supprime *)
- let rec supprime x l =
- match l with
- |[]-> failwith "liste trop courte"
- |h::t-> if h = x
- then
- t
- else
- h::(supprime x t)
- ;;
- (* TEST DE supprime *)
- let test_supprime =
- supprime 4 (1::2::3::4::5::6::7::[]) =(1::2::3::5::6::7::[])
- ;;
- (* FONCTION supprimeMult5 *)
- let rec supprimeMult5 l =
- match l with
- |[]-> []
- |h::t-> if h mod 5 = 0
- then
- supprimeMult5 t
- else
- h::(supprimeMult5 t)
- ;;
- (* TEST DE supprimeMult5 *)
- let test_supprimeMult5 =
- supprimeMult5 (1::2::3::4::5::6::7::8::9::10::[]) = (1::2::3::4::6::7::8::9::[])
- ;;
- (* FONCTION supprimeP *)
- let propriteteP x = x mod 3 = 0;;
- let rec suppr_listeP l p =
- match l with
- |[]-> []
- |h::t-> if (p h)
- then
- suppr_listeP t p
- else
- h::(suppr_listeP t p)
- ;;
- (* TEST DE supprimeP*)
- let test_supprime =
- suppr_listeP (1::2::3::4::5::6::7::8::9::10::[]) propriteteP = (1::2::4::5::7::8::10::[])
- ;;
- (* FONCTION concat *)
- let rec concat l1 l2 =
- match l1 with
- |[]->l2
- |h1::t1->h1::(concat t1 l2)
- ;;
- (* TEST DE concat *)
- let test_concat =
- concat (1::2::3::4::[]) (5::6::7::8::9::[]) = (1::2::3::4::5::6::7::8::9::[])
- ;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement