| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422 |
- type arbre_bin =
- |Vide
- | Noeud of int*(arbre_bin)*(arbre_bin)
- ;;
- let ex1 = Noeud(
- 27,
- Noeud(
- 12,
- Noeud(5,Vide,Vide),
- Noeud(
- 19,
- Noeud(17,Vide,Vide),
- Noeud(
- 24,
- Noeud(20,Vide,Vide),
- Noeud(26,Vide,Vide)
- )
- )
- ),
- Noeud(
- 43,
- Noeud(36,Vide,Vide),
- Noeud(77,Vide,Vide)
- )
- );;
- type comparaison = Inf | Egal | Sup;;
- let compare_int x y =
- if x<y then Inf else if x=y then Egal else Sup
- ;;
- let rec recherche a func x = match a with
- | Vide -> false
- | Noeud(n,g,d)->match func x n with
- | Inf -> recherche g func x
- | Egal -> true
- | Sup -> recherche d func x
- ;;
- (*
-
- C(0)=2
- Opf = Comparaisons
- 2h+2
- *)
- (*a est un arbre de recherche dans tous les programmes suivants*)
- let rec min_gauche_max_droit a max1 min2= match a with
- | Vide -> failwith "Pas de min"
- | N(e,g,d) -> if max1 > min_gauche_max_droit d then max1 else min_gauche_max_droit d;
- if min2 > min_gauche_max_droit a
- ;;
- #trace min_gauche_max_droit;;
- let rec verif_encadre a fuck x y = match a with
- | Vide -> true
- |
- ;;
- let verif_arbre_rech a func = verif_encadre a func (fst (min_gauche_max_droit a)) (snd (min_gauche_max_droit a));;
- let verif_tri l func =
- ;;
- (*Copier la fonction infixe ici*)
- let verif_arb_rech2 a func =
- ;;
- let insere_feuille a func x =
- ;;
- let decoupe a func x =
- ;;
- let insere_racine a func x =
- ;;
- let construction_feuille l func =
- ;;
- let construction_racine l func =
- ;;
- let liste_ex1 = [1;2;3;4;5;6;7;8;9];;
- let liste_ex2 = [1;3;5;7;9;8;6;4;2];;
- let rotation_gauche a =
- ;;
- let rotation_droite a =
- ;;
- let rec mystere a1 a2 func =
- | _,Vide -> a1
- | Vide,_ -> a2
- | Noeud(e1,ag1,ad1), Noeud(e2, ag2,ad1) when compare e1 e2 = Inf
- -> mystere ad1 (Noeud(e2,mystere Noeud(e1,ag1,Vide) ag2 func, ad2)) func
- | Noeud(e1,ag1,ad1), Noeud(e2,ag2,ad2)
- -> mystere ag1 (Noeud(e2,ag2,mystere Noeud(e1,Vide,ad1) ad2 func)) func
- ;;
|