Clean up code of isBST.
This commit is contained in:
parent
baa7ab1459
commit
8977ee3357
|
@ -191,7 +191,10 @@ inorder = treeFoldr (:) []
|
|||
-- True
|
||||
--
|
||||
isBST :: Tree -> Bool
|
||||
isBST tree = snd $ treeFoldl (\v (p, b) -> (v, b && v >= p)) (minInt tree, True) tree
|
||||
isBST tree = snd $ treeFoldl accCompare (firstNum, True) tree
|
||||
where
|
||||
accCompare v (p, b) = (v, b && v >= p)
|
||||
firstNum = leftmost tree
|
||||
|
||||
-- | Check whether a number is contained in a binary search tree.
|
||||
-- (You may assume that the given tree is a binary search tree.)
|
||||
|
|
Loading…
Reference in New Issue
Block a user