查找具有意外错误的BST范围

时间:2019-07-01 17:53:42

标签: haskell binary-tree binary-search-tree

此功能应该能够查找给定BST的范围。所以 如果 low <= x <= high lookupRange低高t 应该返回true。

我想用这个例子来证明我的代码:

lookupRange low high (Node (Node (Node Leaf 1 Leaf) 
                                 2 
                                 (Node Leaf 3 Leaf))  
                           5 
                           (Node (Node Leaf 6 Leaf) 
                                 7 
                                 (Node Leaf 8 Leaf)))
data Tree a = Leaf | Node (Tree a) a (Tree a)
  deriving Show

lookupRange :: Ord a => a -> a -> Tree a -> Bool
lookupRange low high Leaf = False
lookupRange low high (Node l x r) | low <= x && x <= high = True
                                  | x < low               = lookupRange low high r
                                  | otherwise             = lookupRange low high l

在我的示例中,我收到以下错误消息:

<interactive>:11:13: error:
    * Variable not in scope: low :: Integer
    * Perhaps you meant `log' (imported from Prelude)

<interactive>:11:17: error: Variable not in scope: high :: Integer

0 个答案:

没有答案