Adding Haskell examples (#17)

* Adding binary search example for Haskell

* Adding selection sort example in Haskell

* Adding Haskell examples for chapter 3

* Adding examples for chapter 4

* Adding examples for chapter 5

* Adding git ignore

* Add Haskell example for BFS
This commit is contained in:
Bijoy Thomas
2017-06-11 18:12:48 -05:00
committed by Aditya Bhargava
parent c5c2563d05
commit 6f78bdf3d7
13 changed files with 136 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
sumarr [] = 0
sumarr (x: xs) = x + sumarr xs
main = putStrLn (show (sumarr [1,2,3,4]))

View File

@@ -0,0 +1,5 @@
countarr [] = 0
countarr (x:xs) = 1 + countarr xs
main = (putStrLn . show . countarr) [0, 1, 2, 3, 4, 5]

View File

@@ -0,0 +1,6 @@
maxarr (x: []) = x
maxarr (x:xs) = if x > maxofrest then x else maxofrest
where maxofrest = maxarr xs
main = (putStrLn . show . maxarr) [1, 5, 10, 25, 16, 1]

View File

@@ -0,0 +1,8 @@
import Data.List
quicksort [] = []
quicksort (x: []) = [x]
quicksort (x:xs) = (quicksort lessthan) ++ [x] ++ (quicksort greaterthan)
where (lessthan, greaterthan) = partition (<= x) xs
main = (putStrLn . show . quicksort) [0,9,4,5,6,3,1,0,1]