Skip to content

Instantly share code, notes, and snippets.

@nbogie
Created September 13, 2011 23:49
Show Gist options
  • Save nbogie/1215499 to your computer and use it in GitHub Desktop.
Save nbogie/1215499 to your computer and use it in GitHub Desktop.
poor soln h99 problemss: p56 - symmetrical binary trees
main = print $ demo
demo = isSym tree1
-- test data
tree1 = (Branch 'x' (Branch 'x' Empty Empty) (Branch 'x' Empty Empty))
tree2 = (Branch 'x' (Branch 'x' Empty Empty) Empty)
data Tree = Branch Char Tree Tree | Empty
isSym :: Tree -> Bool
isSym Empty = True
isSym (Branch _ left right) = isMirror left right
isMirror :: Tree -> Tree -> Bool
isMirror Empty Empty = True
isMirror (Branch _ _ _) Empty = False
isMirror Empty (Branch _ _ _) = False
isMirror (Branch _ al ar) (Branch _ bl br) = isMirror al br && isMirror ar bl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment