Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,14 @@
// This function performs an insertion sort with an array.
// The input parameter is a generic array (any type that can perform comparison).
// As is typical of functional programming style the input array is not modified;
// a copy of the input array is made and modified and returned.
let insertionSort (A: _ array) =
let B = Array.copy A
for i = 1 to B.Length - 1 do
let mutable value = B.[i]
let mutable j = i - 1
while (j >= 0 && B.[j] > value) do
B.[j+1] <- B.[j]
j <- j - 1
B.[j+1] <- value
B // the array B is returned

View file

@ -0,0 +1,15 @@
let insertionSort collection =
// Inserts an element into its correct place in a sorted collection
let rec 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
| [], _ -> acc
| x::xs, ys -> xs |> isort (sinsert x ys)
collection |> isort []