tp4.ml 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. type arbre_bin =
  2. |Vide
  3. | Noeud of int*(arbre_bin)*(arbre_bin)
  4. ;;
  5. let ex1 = Noeud(
  6. 27,
  7. Noeud(
  8. 12,
  9. Noeud(5,Vide,Vide),
  10. Noeud(
  11. 19,
  12. Noeud(17,Vide,Vide),
  13. Noeud(
  14. 24,
  15. Noeud(20,Vide,Vide),
  16. Noeud(26,Vide,Vide)
  17. )
  18. )
  19. ),
  20. Noeud(
  21. 43,
  22. Noeud(36,Vide,Vide),
  23. Noeud(77,Vide,Vide)
  24. )
  25. );;
  26. type comparaison = Inf | Egal | Sup;;
  27. let compare_int x y =
  28. if x<y then Inf else if x=y then Egal else Sup
  29. ;;
  30. let rec recherche a func x = match a with
  31. | Vide -> false
  32. | Noeud(n,g,d)->match func x n with
  33. | Inf -> recherche g func x
  34. | Egal -> true
  35. | Sup -> recherche d func x
  36. ;;
  37. (*
  38. C(0)=2
  39. Opf = Comparaisons
  40. 2h+2
  41. *)
  42. (*a est un arbre de recherche dans tous les programmes suivants*)
  43. let rec min_gauche_max_droit a max1 min2= match a with
  44. | Vide -> failwith "Pas de min"
  45. | N(e,g,d) -> if max1 > min_gauche_max_droit d then max1 else min_gauche_max_droit d;
  46. if min2 > min_gauche_max_droit a
  47. ;;
  48. #trace min_gauche_max_droit;;
  49. let rec verif_encadre a fuck x y = match a with
  50. | Vide -> true
  51. |
  52. ;;
  53. let verif_arbre_rech a func = verif_encadre a func (fst (min_gauche_max_droit a)) (snd (min_gauche_max_droit a));;
  54. let verif_tri l func =
  55. ;;
  56. (*Copier la fonction infixe ici*)
  57. let verif_arb_rech2 a func =
  58. ;;
  59. let insere_feuille a func x =
  60. ;;
  61. let decoupe a func x =
  62. ;;
  63. let insere_racine a func x =
  64. ;;
  65. let construction_feuille l func =
  66. ;;
  67. let construction_racine l func =
  68. ;;
  69. let liste_ex1 = [1;2;3;4;5;6;7;8;9];;
  70. let liste_ex2 = [1;3;5;7;9;8;6;4;2];;
  71. let rotation_gauche a =
  72. ;;
  73. let rotation_droite a =
  74. ;;
  75. let rec mystere a1 a2 func =
  76. | _,Vide -> a1
  77. | Vide,_ -> a2
  78. | Noeud(e1,ag1,ad1), Noeud(e2, ag2,ad1) when compare e1 e2 = Inf
  79. -> mystere ad1 (Noeud(e2,mystere Noeud(e1,ag1,Vide) ag2 func, ad2)) func
  80. | Noeud(e1,ag1,ad1), Noeud(e2,ag2,ad2)
  81. -> mystere ag1 (Noeud(e2,ag2,mystere Noeud(e1,Vide,ad1) ad2 func)) func
  82. ;;