-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectionSort.hs
More file actions
33 lines (26 loc) · 803 Bytes
/
SelectionSort.hs
File metadata and controls
33 lines (26 loc) · 803 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
{- |
Module : SelectionSort.hs
Description : Module implements the selection sort algorithm
Copyright : (c) David Oniani
License : MIT License
Maintainer : onianidavid@gmail.com
Stability : provisional
Portability : portable
For more information, follow the link below.
https://en.wikipedia.org/wiki/Selection_sort
-}
module SelectionSort where
-- | Selection sort
selectionSort :: (Ord a) => [a] -> [a]
selectionSort [] = []
selectionSort xs = let x = maximum xs in selectionSort (delete x xs) ++ [x]
where
delete _ [] = []
delete y (x:xs)
| x == y = xs
| otherwise = x : delete y xs
main :: IO ()
main = do
let arr = [12,1,6,31,99,25,3,56,21,6]
putStr "The sorted version of the array is "
print (selectionSort arr)