Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type Tas = Vide | Noeud of int * Tas * Tas;;
- let monTas =
- Noeud(1,
- Noeud(4,
- Noeud(5, Vide, Vide),
- Noeud(7,
- Noeud(9,
- Noeud(14, Vide, Vide),
- Vide),
- Noeud(8, Vide, Vide))),
- Noeud(2,
- Noeud(6, Vide, Vide),
- Noeud(3, Vide, Vide)));;
- let min_tas T = match T with
- | Vide -> failwith "Tas vide.";
- | Noeud(r, f, g) -> r;;
- let rec enleve_min tas = match tas with
- | Vide -> Vide;
- | Noeud(m, Vide, Vide) -> Vide;
- | Noeud(m, Vide, f) -> Noeud(min_tas f, enleve_min f, Vide);
- | Noeud(m, f, Vide) -> Noeud(min_tas f, enleve_min f, Vide);
- | Noeud(m, g, d) -> let mg = min_tas g and md = min_tas d in
- if (mg < md) then
- Noeud(mg, enleve_min g, d)
- else
- Noeud(md, g, enleve_min d);;
- let rec ajout tas x = match tas with
- | Vide -> Noeud(x, Vide, Vide);
- | Noeud(m, g, d) -> if x <= m then Noeud(x, d, ajout g m)
- else Noeud(m, d, ajout g x);;
- let ajouter_liste l =
- let rec aux l acc = match l with
- | [] -> acc
- | t::q -> aux q (ajout acc t);
- in aux l Vide;;
- let rec vider tas = match tas with
- | Vide -> []
- | Noeud(m, Vide, Vide) -> [m];
- | Noeud(m, Vide, d) -> m::(vider d);
- | Noeud(m, g, Vide) -> m::(vider g);
- | Noeud(m, g, d) -> m::(vider (enleve_min tas));;
- vider monTas;;
- let rec triParTas liste = vider (ajouter_liste liste);;
- let test = triParTas [2; 1; 45; 6; 3; 6; 0; 8; 69; 45; 89];;
Advertisement
Add Comment
Please, Sign In to add comment