-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraph.hs
More file actions
24 lines (20 loc) · 748 Bytes
/
Copy pathGraph.hs
File metadata and controls
24 lines (20 loc) · 748 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
module Graph(
conn_comp
) where
import Data.Maybe
import Data.List
edgeOf :: (Eq a) => (a,a) -> [a] -> Bool
edgeOf (x,y) v = (x `elem` v) || (y `elem` v)
conn_comp' :: (Eq a) => (a,a)->[[a]]->[[a]]
conn_comp' e vs = conn e vs Nothing
where conn :: (Eq a) => (a,a) -> [[a]] -> Maybe [a] -> [[a]]
conn _ [] Nothing = []
conn _ [] (Just v) = [v]
conn e (v:vs) Nothing
| edgeOf e v = conn e vs (Just v)
| otherwise = v:(conn e vs Nothing)
conn e (v:vs) (Just w)
| edgeOf e v = (v++w):vs
| otherwise = v:(conn e vs (Just w))
conn_comp :: (Eq a) => [(a,a)] -> [a] -> [[a]]
conn_comp es vs = foldr conn_comp' [[v] | v<-vs] es