-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgml.hs
More file actions
90 lines (67 loc) · 2.14 KB
/
gml.hs
File metadata and controls
90 lines (67 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
--Questão 1
tiraEspaco :: String -> String
tiraEspaco [] = []
tiraEspaco (s:tr)
|s == ' ' = tiraEspaco tr
|otherwise = (s : (tiraEspaco tr))
concatStr :: String -> String -> String
concatStr str strgs = str ++ (tiraEspaco str)
main :: IO ()
main = do
str <- getLine
if(str == "")
then putStrLn (tiraEspaco str)
else putStr ""
main
--funcionando sem salvar
main' :: IO ()
main' = do
str <- getLine
putStrLn (tiraEspaco str)
main'
{-
--lembrar como fazer aquele negócio de
a <- getLine
b <- fun a main
fun :: String -> String
fun str
|str /= '' = (tiraEspaco str)
|otherwise =
-}
--Questão 2
data Graph t = NulG | No [t] [(t, t)]
deriving (Show, Eq)
data Tree t = NulT | Nod t (Tree t) (Tree t)
deriving (Eq, Ord, Show)
tree :: (Num t) => Tree t
tree = Nod 3 (Nod 4 NulT NulT) (Nod 7 NulT (Nod 0 NulT NulT))
member :: Eq t => [t] -> t -> Bool
member list x = (length [l | l <- list , l == x]) > 0
{-
checkMembership :: [t] -> t -> t -> t ->
checkMembership nos a b c
|member nos a =
-}
toGraph :: t -> t -> t -> Graph t
toGraph a e r = No [a, e , r] [(a, e), (a, r)]
--toGraph (No nos edges) a e r = No (checkMembership nos a e r)
toGraphEsq :: t -> t -> Graph t
toGraphEsq a e = No [a, e] [(a, e)]
toGraphDir :: t -> t -> Graph t
toGraphDir a r = No [a, r] [(a, r)]
blend :: Graph t -> Graph t -> Graph t -> Graph t
blend graph NulG NulG = graph
blend (No nos edges) (No noEsq edEsq) NulG = No (nos ++ noEsq) (edges ++ edEsq)
blend (No nos edges) NulG (No noDir edDir) = No (nos ++ noDir) (edges ++ edDir)
blend (No nos edges) (No noEsq edEsq) (No noDir edDir) = No (nos ++ noEsq ++noDir) (edges ++ edDir ++ edEsq)
transforma :: Tree t -> Graph t
transforma NulT = NulG
transforma (Nod n NulT NulT) = No [n] []
transforma (Nod n (Nod e x y) NulT) = blend ((toGraphEsq n e) (transforma (Nod e x y)) NulG)
transforma (Nod n NulT (Nod r z v)) = blend ((toGraphDir n r) NulG (transforma (Nod r z v)))
transforma (Nod n (Nod e x y) (Nod r z v)) = blend ((toGraph n e r) (transforma (Nod e x y)) (transforma (Nod r z v)))
{-
criarGrafo :: [Tree t] -> Graph t
criarGrafo NulT = NulG
criarGrafo (tr:trs) = (transforma tr)
-}