diff --git a/HW1.fedorind.hs b/HW1.fedorind.hs index 6456dca..0cc2240 100644 --- a/HW1.fedorind.hs +++ b/HW1.fedorind.hs @@ -191,12 +191,7 @@ inorder = treeFoldr (:) [] -- True -- isBST :: Tree -> Bool -isBST (Leaf _) = True -isBST (Node i l r) = i >= value l && i <= value r && isBST l && isBST r - where - value (Leaf i) = i - value (Node i _ _) = i - +isBST tree = snd $ treeFoldl (\v (p, b) -> (v, b && v >= p)) (minInt tree, True) tree -- | Check whether a number is contained in a binary search tree. -- (You may assume that the given tree is a binary search tree.)