all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
|
|
@ -0,0 +1,15 @@
|
|||
import Data.Graph.Inductive.Internal.Heap(
|
||||
Heap(..),insert,findMin,deleteMin)
|
||||
|
||||
-- heapsort is added in this module as an example application
|
||||
|
||||
build :: Ord a => [(a,b)] -> Heap a b
|
||||
build = foldr insert Empty
|
||||
|
||||
toList :: Ord a => Heap a b -> [(a,b)]
|
||||
toList Empty = []
|
||||
toList h = x:toList r
|
||||
where (x,r) = (findMin h,deleteMin h)
|
||||
|
||||
heapsort :: Ord a => [a] -> [a]
|
||||
heapsort = (map fst) . toList . build . map (\x->(x,x))
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
*Main> heapsort [[6,9],[2,13],[6,8,14,9],[10,7],[5]]
|
||||
[[2,13],[5],[6,8,14,9],[6,9],[10,7]]
|
||||
Loading…
Add table
Add a link
Reference in a new issue