Sorting algorithms/Selection sort: Difference between revisions

Content deleted Content added
No edit summary
Line 552: Line 552:
let rec ssort = function
let rec ssort = function
[] -> []
[] -> []
| l ->
| x::xs ->
let minrest l =
let min, rest =
let rec aux list min acc=
List.fold_left (fun (min,acc) x ->
match list with
if h<min then (h, min::acc)
[] -> min,acc
else (min, h::acc))
| h::t ->
(x, []) xs
if h<min then aux t h (min::acc)
else aux t min (h::acc)
in aux (List.tail l) (List.head l) []
in
let (min,rest) = minrest l
in min::ssort rest
in min::ssort rest
</lang>
</lang>