1 import Prelude hiding (Ord)
5 data Tree = Leaf Integer | Node Integer Tree Tree
8 -- Ord datatype + show + compare
9 data Ord = BottomUp | TopDown
11 instance Show Ord where
12 showsPrec p (BottomUp) = showString "BottomUp"
13 showsPrec p (TopDown) = showString "TopDown"
15 instance Main.Eq Ord where
16 a == b = show a == show b
18 -- Die eigentliche aufgabe
19 writeLayer :: Tree -> Ord -> [Layer]
20 writeLayer (Leaf x) o = [[x]]
21 writeLayer (Node x l r) o | (o == BottomUp) = (mmerge (writeLayer l o) (writeLayer r o)) ++ [[x]]
22 writeLayer (Node x l r) o | (o == TopDown) = [[x]] ++ (mmerge (writeLayer l o) (writeLayer r o))
24 mmerge :: [[Integer]] -> [[Integer]] -> [[Integer]]
25 mmerge x y = [x!!index ++ y!!index | index <- [0..(min (length x) (length y))-1]]
30 data STree = Nil | SNode Integer STree STree deriving Show
32 transform :: Tree -> STree
33 transform t = toStree (sort (undup (concat (writeLayer t BottomUp))))
35 undup :: [Integer] -> [Integer]
37 undup (x:xs) = x : undup (filter (\y -> not (x == y)) xs)
39 toStree :: [Integer] -> STree
41 toStree (x:xs) = (SNode x Nil (toStree xs))
48 newtype Graph = Graph [(Vertex,[(Vertex,Cost)])]
50 instance Show Graph where
51 showsPrec p (Graph(x)) = showString "Graph(" . shows x . showChar ')'
54 data Result = Yes | No | Invalid
55 instance Show Result where
56 showsPrec p (Yes) = showString "Yes"
57 showsPrec p (No) = showString "No"
58 showsPrec p (Invalid) = showString "Invalid"
60 instance Main.Eq Result where
61 a == b = show a == show b
64 path :: Graph -> Vertex -> Vertex -> Cost -> Result
65 path _ _ _ _ = Invalid
70 --minpath :: Graph -> Vertex -> Vertex -> ([Vertex],Cost)
71 --minpath _ _ _ _ = ([],1337)