Module Heapsort
module HeapsortFun (E: ORDERED) : (SORT with type elem = E.t) =
struct
module H = HeapFun (E) (* One can also use MHeapFun *)
type elem = E.t
let rec hsort (l,h) =
if H.is_empty h
then (l,h)
else
let (max,h') = H.delete_max h
in hsort (max::l, h')
let sort l =
let h = H.heap_of_list l (* h: heap: teilsortiert *)
in fst (hsort ([ ],h))
end
January 31, 2002