Binary Tree Traversal.
8 Mar
2005
8 Mar
'05
11:53 p.m.
data BinTree a = Nil | Node a (BinTree a) (BinTree a) inorder2 :: BinTree a -> [a] -> [a] inorder2 Nil xs = [] inorder2 (Node val b1 b2) xs = (inorder2 b1 (val:(inorder2 b2 (xs)))) I want to be able to traverse across the binary tree in order and that is what I have so far. But somehow it always return []. it seems to ignore the "val:" Y. C.
10 Mar
10 Mar
5:02 p.m.
Paul, Are you sure this isn't homework? ;)
data BinTree a = Nil | Node a (BinTree a) (BinTree a)
inorder2 :: BinTree a -> [a] -> [a] inorder2 Nil xs = [] inorder2 (Node val b1 b2) xs = (inorder2 b1 (val:(inorder2 b2 (xs))))
Review the case for []. What does the parameter xs represent? How should it be involved in constructing the result? HTH, Stefan
7842
Age (days ago)
7844
Last active (days ago)
1 comments
2 participants
participants (2)
-
Paul Chen -
Stefan Holdermans