/ Published in: Haskell
URL: http://antilamer.livejournal.com/289527.html
Similar to merging two sorted lists. UPT: Doesn't work.
Expand |
Embed | Plain Text
cmp Empty Empty = Equal cmp Empty t2 = NotEqual cmp t1 Empty = Remains t1 cmp t1@(Node v1 l1 r1) t2@(Node v2 l2 r2) | v1 == v2 = case (cmp l1 l2) of Equal -> (cmp r1 r2) _ -> NotEqual | v1 < v2 = if l2 == Empty then NotEqual else case (cmp t1 l2) of Equal -> NotEqual NotEqual -> NotEqual Remains t1' -> cmp t1' (Node v2 Empty r2) else case (cmp t2 l1) of Equal -> NotEqual NotEqual -> NotEqual Remains t2' -> cmp (Node v1 Empty r1) t2' t1 == t2 = (cmp t1 t2) == Equal
Comments
Subscribe to comments
You need to login to post a comment.

The source you posted compiles and works correctly for me. It is only deliberately obfuscated. The result of the second and third case at lines 16 to 26 is always
NotEqual, becauseRemains ..can never result from line 17 resp. 23.As for comparing two trees, the following will do nicely: