Skip to content
Browse files

64'

  • Loading branch information...
1 parent 008aa62 commit 3391277e7bfbe63d50e944b11f5f8c5b0f2a252c @tianyicui committed
Showing with 8 additions and 1 deletion.
  1. +8 −1 BinaryTrees.hs
View
9 BinaryTrees.hs
@@ -144,4 +144,11 @@ treeZipWith f (Branch x1 l1 r1) (Branch x2 l2 r2) =
treeZipWith3 f t1 t2 t3 =
treeZipWith ($) (treeZipWith f t1 t2) t3
-layout t = treeZipWith3 (\x y z -> (x,(y,z))) t (inorder t) (depth t)
+layout64 t = treeZipWith3 (\x y z -> (x,(y,z))) t (inorder t) (depth t)
+
+-- from http://www.haskell.org/haskellwiki/99_questions/Solutions/64
+layout64' t = fst (layoutAux 1 1 t)
+ where layoutAux x y Empty = (Empty, x)
+ layoutAux x y (Branch a l r) = (Branch (a, (x',y)) l' r', x'')
+ where (l', x') = layoutAux x (y+1) l
+ (r', x'') = layoutAux (x'+1) (y+1) r

0 comments on commit 3391277

Please sign in to comment.
Something went wrong with that request. Please try again.