Clean up code of isBST.

This commit is contained in:
Danila Fedorin 2019-01-18 11:20:02 -08:00
parent baa7ab1459
commit 8977ee3357

View File

@ -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.)