Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module PriorityQueue where
- import qualified Data.List as L
- type Point = (Int, Int)
- data Node = Node { point :: Point
- ,parent :: Maybe Node
- ,g :: Double
- ,h :: Double
- } deriving (Show)
- instance Eq Node where
- -- (==) = on (==) (g + h) -- miks ei toimi
- (Node a1 parent1 g1 h1) == (Node a2 parent2 g2 h2) = (g1 + h1) == (g2 + h2)
- instance Ord Node where
- -- (>=) = on (>=) (g + h) -- miks ei toimi
- (Node a1 parent1 g1 h1) `compare` (Node a2 parent2 g2 h2) = (g1 + h1) `compare` (g2 + h2)
- priority :: Node -> Double
- priority (Node a parent g h) = g + h
- getHighestPrioElem :: [Node] -> Maybe Node
- getHighestPrioElem [] = Nothing
- getHighestPrioElem xs = Just $ head (L.sort xs)
- popHighestPrioElem :: [Node] -> Maybe [Node]
- popHighestPrioElem [] = Nothing
- popHighestPrioElem xs = Just $ tail (L.sort xs)
- insertWithPriority :: Node -> [Node] -> [Node]
- insertWithPriority node xs
- = L.sort (node:xs)
Add Comment
Please, Sign In to add comment