Menu

Display Left Leaf Binary Tree Haskell Given Following Information Create Haskell Function Q43870100

Display left most leaf of a binary tree in Haskell

Given the following information:

-- | Integer-labeled binary trees. data Tree = Node Int Tree Tree -- ^ Internal nodes | Leaf Int -- ^ Leaf nodes deriving_(Eq

Create a Haskell function to show the following results when thefunction is entered.

— >>> leftmost (Leaf 3)

— 3

—

— >>> leftmost (Node 5 (Leaf 6) (Leaf 7))

— 6

—

— >>> leftmost t1

— 4

—

— >>> leftmost t2

— 1

— | Integer-labeled binary trees. data Tree = Node Int Tree Tree — ^ Internal nodes | Leaf Int — ^ Leaf nodes deriving_(Eq, Show) — | An example binary tree, which will be used in tests. ti :: Tree t1 = Node 1 (Node 2 (Node 3 (Leaf 4) (Leaf 5)), (Leaf 6)) (Node 7 (Leaf 8) (Leaf 9)) — Another example binary tree, used in tests. t2 :: Tree t2 = Node 6 (Node 2 (Leaf 1) (Node 4 (Leaf 3) (Leaf 5))) 1 (Node 8 (Leaf 7) (Leaf 9)) Show transcribed image text — | Integer-labeled binary trees. data Tree = Node Int Tree Tree — ^ Internal nodes | Leaf Int — ^ Leaf nodes deriving_(Eq, Show) — | An example binary tree, which will be used in tests. ti :: Tree t1 = Node 1 (Node 2 (Node 3 (Leaf 4) (Leaf 5)), (Leaf 6)) (Node 7 (Leaf 8) (Leaf 9)) — Another example binary tree, used in tests. t2 :: Tree t2 = Node 6 (Node 2 (Leaf 1) (Node 4 (Leaf 3) (Leaf 5))) 1 (Node 8 (Leaf 7) (Leaf 9))

Expert Answer


Answer to Display left most leaf of a binary tree in Haskell Given the following information: Create a Haskell function to show th…

OR