Sanchime.Learn/Algrithms/Sorts/SelectSort.fs

17 lines
453 B
Forth
Raw Normal View History

2022-07-05 20:26:22 +08:00
namespace Sanchime.Algrithm.Sort
[<AutoOpen>]
module Select =
let rec ssort sorted = function
| [] -> []
| xs ->
let mini = xs |> List.min
let xs' = (mini, xs) |> select sorted
mini::(ssort sorted xs')
// 将最小值移至列表开头
and select sorted = function
| _, [] -> []
| x, y::ys ->
if sorted x y then ys
else y::(select sorted (x, ys))