Skip to content

Instantly share code, notes, and snippets.

@lhitori
Created March 15, 2026 08:45
Show Gist options
  • Select an option

  • Save lhitori/d1a99abf8972c66eac042e283e20e21c to your computer and use it in GitHub Desktop.

Select an option

Save lhitori/d1a99abf8972c66eac042e283e20e21c to your computer and use it in GitHub Desktop.
Tri Fusion en OCaml
(* Implémentation du Tri Fusion en OCaml *)
let rec separer : 'a list -> 'a list * 'a list = function
| [] -> ([], [])
| [ x ] -> ([ x ], [])
| x :: y :: tl ->
let xs, ys = separer tl in
(x :: xs, y :: ys)
and fusionner : 'a list * 'a list -> 'a list = function
| [], l | l, [] -> l
| x :: xs, y :: ys ->
if x < y then x :: fusionner (xs, y :: ys)
else y :: fusionner (x :: xs, ys)
and trier : 'a list -> 'a list = function
| [] -> []
| [ x ] -> [ x ]
| xs ->
let ys, zs = separer xs in
fusionner (trier ys, trier zs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment