I am trying to search through a TriTree.
I have this type for my Tree and here's my search function for NodeTwo:
data TriTree a
= Empty
| NodeOne a (TriTree a) (TriTree a) (TriTree a)
| NodeTwo a a (TriTree a) (TriTree a) (TriTree a)
deriving (Show)
search :: Ord a => a -> TriTree a -> Bool
search _ Empty = False
search x (NodeOne v a b c) = x == v || x `search` a || x `search` b || x `search` c
search x (NodeTwo u v a b c) = x == u || x == v || x `search` a || x `search` b || x `search` c
search x _ = undefined
Someone else had the same question; we're given the type but need to implement search. Is the search function I implemented for NodeTwo is valid? Is it even pattern matching if this doesn't handle both NodeOne and Node two within one call?