HOME

The Haskell Project

Introduction

Add something here ...


~kc4zvw:

  

Notes

Add something here ...

Header 2

Add something here ...


  

Header 3

Add something here ...

The 'heapsort' Algorithm

Add something here ...


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))

  



kc4zvw@www:~$ ghci
GHCi, version 8.8.4: https://www.haskell.org/ghc/  :? for help
Prelude> :load heapsort.hs
[1 of 1] Compiling Main             ( heapsort.hs, interpreted )
Ok, one module loaded.
*Main> heapSort [9,5,8,2,1,4,6,3,0,7]
[0,1,2,3,4,5,6,7,8,9]
*Main> :quit
Leaving GHCi.
kc4zvw@www:~$

  

Miscellaneous

Add something here ...

  1. Links ...
  2. Links ...
  3. Links ...





Revised: Tuesday, March 21, 2023 at 18:59:21 PM (EDT)