Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type Tas = {tab : int vect ; mutable taille : int };;
- (* Tas d'exemple. *)
- let monTas = {
- tab = make_vect 255 0;
- taille = 9
- };;
- monTas.tab.(0) <- 9;
- monTas.tab.(1) <- 8;
- monTas.tab.(2) <- 7;
- monTas.tab.(3) <- 6;
- monTas.tab.(4) <- 1;
- monTas.tab.(5) <- 5;
- monTas.tab.(6) <- 3;
- monTas.tab.(7) <- 2;
- monTas.tab.(8) <- 4;;
- (* Fin du tas d'exemple. *)
- let rec max_noeud tas i =
- if 2 * i + 1 > tas.taille - 1 then
- i;
- else (
- if 2 * 1 + 2 > tas.taille then
- max tas.tab.(i) tas.tab.(2 * i + 1)
- else
- max (tas.tab.(i))
- (max (max_noeud tas(2 * i + 1)) (max_noeud tas (2 * i + 2)))
- );;
- let max_noeud tas i =
- if 2 * i + 1 > tas.taille - 1 then
- i
- else (
- if tas.tab.(i) <= 2 * tas.tab.(2 * i + 1) then
- 2 * i + 1
- else (
- if tas.tab.(i) < tas.tab.(2 * i + 1) || tas.tab.(i) < tas.tab.(2 * i + 2) then (
- if tas.tab.(2 * i + 1) > tas.tab.(2 * i + 2) then (
- 2 * i + 2
- )
- else
- (
- 2 * i + 2
- )
- )
- else
- (
- 2 * i + 1
- )
- )
- );;
- let m = max_noeud monTas 3;;
- /*let entasser tas i =
- if tas.tab.(i)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement