Skip to content

Instantly share code, notes, and snippets.

@jayendra13
Created April 7, 2022 12:32
Show Gist options
  • Save jayendra13/a16af04a5779e48207c7a3c6106330dd to your computer and use it in GitHub Desktop.
Save jayendra13/a16af04a5779e48207c7a3c6106330dd to your computer and use it in GitHub Desktop.
module Main where
-- http://files.farka.eu/pub/AC21007/lec5.pdf
insSortImpl :: [Int] -> [Int] -> [Int]
insSortImpl sorted [] = sorted
insSortImpl sorted (x:xs) =
insSortImpl (insert x sorted) xs
where
insert y [] = [y]
insert y (z:zs) = if y < z
then y : (z:zs)
else z : (insert y zs)
insSort :: [Int] -> [Int]
insSort x = insSortImpl [] x
main = print(insSort [8,7,1,6])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment