Code source du tri "fusion"

let fusion tableau deb1 fin1 fin2=
  let deb2=fin1+1 and tableau_bis=(Array.make (fin1-deb1+1) 0) in
  let compt1=ref(deb1) and compt2=ref(deb2) in
  
  for i=deb1 to fin1 do
    tableau_bis.(i-deb1)<-tableau.(i) (* recopie de la premiére partie du tableau *)
  done;
  
  for i=deb1 to fin2 do
    if (!compt1)=deb2 then
      ()
    else if (!compt2)=(fin2+1) then
      begin
        tableau.(i)<-tableau_bis.(!compt1-deb1);
        compt1:=(!compt1)+1
      end
    else if tableau_bis.(!compt1-deb1) < tableau.(!compt2) then
      begin
        tableau.(i)<-tableau_bis.(!compt1-deb1);
        compt1:=(!compt1)+1
      end
    else
      begin
        tableau.(i)<-tableau.(!compt2);
        compt2:=(!compt2)+1;
      end
  done;;
(*  val fusion : int array -> int -> int -> int -> unit = <fun> *)
  
let tri_fusion tableau=

  let rec tri_fusion_bis tableau debut fin=
    if debut<>fin then
      begin
        let milieu=(debut+fin)/2 in
        tri_fusion_bis tableau debut milieu;
        tri_fusion_bis tableau (milieu+1) fin;
        fusion tableau debut milieu fin;
      end;

  in let longueur=(Array.length tableau) in
    if (longueur>0) then
      tri_fusion_bis tableau 0 (longueur-1);;
(* val tri_fusion : int array -> unit = <fun> *)