| Copyright | Copyright (C) 2021 Yoo Chung |
|---|---|
| License | GPL-3.0-or-later |
| Maintainer | dev@chungyc.org |
| Safe Haskell | Safe-Inferred |
| Language | GHC2021 |
Problems.P56
Description
Part of Ninety-Nine Haskell Problems. Some solutions are in Solutions.P56.
Documentation
symmetric :: Tree a -> Bool Source #
Let us call a binary tree symmetric if you can draw a vertical line through the root node
and then the right subtree is the mirror image of the left subtree.
Write a function symmetric to check whether a given binary tree is symmetric.
We are only interested in the structure, not in the contents of the nodes.
Examples
>>>symmetric (Branch 'x' (Branch 'x' Empty Empty) Empty)False
>>>symmetric (Branch 'x' (Branch 'x' Empty Empty) (Branch 'x' Empty Empty))True
Hint
Write a function mirror first to check whether one tree is the mirror image of another.