Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
(* 1.2 Tris recursifs **************************************************) (* 1.2.1 Tri par insertion *) let rec insererEntier n = function [] -> [n] | a::l when a a::(insererEntier n l) | l -> n::l;; let rec triEntier = function [] -> [] | a::l -> insererEntier a (triEntier l);; let l = [9;1;6;0;2;3;5;4;7;8];; triEntier l;; let rec inserer comp n = function [] -> [n] | a::l when comp a n -> a::(inserer comp n l) | l -> n::l;; let rec triInsere comp = function [] -> [] | a::l -> inserer comp a (triInsere comp l);; triInsere (fun a b -> a > b) l;; (* 1.2.2 Quicksort *) let rec divise comp a = function [] -> [],[] | n::l -> let (l1,l2) = divise comp a l in if comp a n then l1,n::l2 else n::l1,l2;; let rec triQuick comp = function [] -> [] | [n] -> [n] | a::l -> let (l1,l2) = divise comp a l in (triQuick comp l1)@[a]@(triQuick comp l2);; triQuick (<) l;; let bigList = let build n = let rec b = function 0 -> [] | m -> (Random.int n)::(b (m-1)) in b n in build 5000;; triQuick (<) bigList;; triInsere (<) bigList;;