17 lines
453 B
Forth
17 lines
453 B
Forth
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)) |