Created
September 13, 2011 23:49
-
-
Save nbogie/1215499 to your computer and use it in GitHub Desktop.
poor soln h99 problemss: p56 - symmetrical binary trees
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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