diff options
author | Determinant <ted.sybil@gmail.com> | 2017-05-30 21:57:26 -0400 |
---|---|---|
committer | Determinant <ted.sybil@gmail.com> | 2017-05-30 21:57:26 -0400 |
commit | e0fff7c4014512bf88b23136dbbb426d9d9b7511 (patch) | |
tree | 91a824a850b3e5f0d60f1f065e092e4accee9790 /61-69/66.hs | |
parent | 626a548f0ef51b5ee1d3ba049330317f94c89f99 (diff) |
finish vol 7
Diffstat (limited to '61-69/66.hs')
-rw-r--r-- | 61-69/66.hs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/61-69/66.hs b/61-69/66.hs new file mode 100644 index 0000000..8a3f69c --- /dev/null +++ b/61-69/66.hs @@ -0,0 +1,17 @@ +data Tree a = Empty | Branch a (Tree a) (Tree a) deriving (Show, Eq) + +layout :: Tree Char -> Tree (Char, (Int, Int)) + +-- layout': the second component of result is the distance of left edge to the +-- axis of root, and the thrid is the distance of right edge. + +layout t = let (ret, ld, _) = layout' t x0 1 + x0 = 1 + maximum ld in ret + where layout' :: Tree Char -> Int -> Int -> (Tree (Char, (Int, Int)), [Int], [Int]) + layout' Empty x y = (Empty, [], []) + layout' (Branch v l r) x y = (Branch (v, (x, y)) lt rt, ld, rd) + where (lt, lld, lrd) = layout' l (x - hsep) (y + 1) + (rt, rld, rrd) = layout' r (x + hsep) (y + 1) + hsep = 1 + (maximum $ 0:zipWith (+) lrd rld) `div` 2 + ld = 0:map (+ hsep) lld + rd = 0:map (+ hsep) rrd |