Code source tri par "insertion"

let tri_insertion tableau=
    let longueur=(Array.length tableau)-1 in
    
    for i=1 to longueur do
      let memoire=tableau.(i) and compteur=ref(i-1) and echange=ref(true) in
      while(!echange) do
        if tableau.(!compteur)>memoire then
          begin
            tableau.(!compteur+1)<-tableau.(!compteur);
            compteur:=(!compteur)-1;
            if (!compteur<0) then echange:=false;
          end
        else
          echange:=false;          
      done;
      tableau.(!compteur+1)<-memoire;
    done;;
(* val tri_insertion : 'a array -> unit = <fun> *)