data Tree a = Nil | Leaf a | Node a (Tree a) (Tree a) root Nil = undefined root (Leaf x) = x root (Node x _ _) = x left Nil = undefined left (Leaf _) = Nil left (Node _ branch _) = branch right Nil = undefined right (Leaf _) = Nil right (Node _ _ branch) = branch tree = Node 1 (Node 2 (Leaf 10) (Leaf 11)) (Node 5 Nil (Leaf 4)) preord Nil = [] preord n = (preord $ left n) ++ [(root n)] ++ (preord $ right n) -- cu ++ (root n) ++ vezi eroare tip la preord tree -- BFS bfs tree = bfsR [tree] -- pe frontiera bfsR [] = [] bfsR (Nil : open) = bfsR open bfsR (n : open) = (root n) : bfsR (open ++ [cL, cR]) where {cL = left n; cR = right n} ----------------------------- theGraph = [(1, 2), (1, 4), (2, 1), (2, 3), (3, 5), (3, 6), (5, 6), (6, 1)]