Sorting algorithms/Insertion sort: Difference between revisions

Line 1,079:
Functional Version
<lang fsharp>
// Inserts an element into its correct place in a sorted collection
let rec private sinsert element collection =
match element, collection with
| x, [] -> [x]
| x, y::ys when x < y -> x::y::ys
| x, y::ys -> y :: (ys |> sinsert x)
 
 
// Performs Insertion Sort
 
let insertionSort collection =
 
// Inserts an element into its correct place in a sorted collection
let rec private sinsert element collection =
match element, collection with
| x, [] -> [x]
| x, y::ys when x < y -> x::y::ys
| x, y::ys -> y :: (ys |> sinsert x)
 
// Performs Insertion Sort
let rec isort acc collection =
match collection, acc with