(* tri par insertion *) let rec inserer x l = match l with [] -> [x] y::s -> if x<=y then x::l else y::(inserer x s) let rec inserer rel_ordre x l = match l with [] -> [x] y::s -> if rel_ordre x y then x::l else y::(inserer rel_ordre x s) let rec trier rel_ordre l = match l with [] -> [] x::s -> inserer rel_ordre x (trier rel_ordre s) let _ = trier (<=) [6; 1; 9; 4; 3] let _ = trier (>=) [6; 1; 9; 4; 3] (* tri rapide *) let rec partage p l = match l with [] -> ([] , []) x::s -> let g,d = partage p s in if x<=p then (x::g , d) else (g , x::d) let rec quicksort l = match l with [] -> [] p::s -> let g , d = partage p s in (quicksort g)@[p]@(quicksort d)
This document was generated using caml2html