14 lines
400 B
Forth
14 lines
400 B
Forth
namespace Sanchime.Algrithm.Sort
|
|
[<AutoOpen>]
|
|
module Insert =
|
|
|
|
let rec isort sorted = function
|
|
| [] -> []
|
|
| [x] -> [x]
|
|
| x::xs -> xs |> isort sorted |> insert sorted x
|
|
|
|
// 将一个元素插入至列表开头
|
|
and insert sorted value = function
|
|
| [] -> [value]
|
|
| x::xs -> if sorted value x then value::x::xs else x :: insert sorted value xs
|
|
|