我在Haskell中实现了二进制搜索树
data BST = Nil | Node (BST) Int (BST) deriving Show
emptyTree :: BST
emptyTree = Nil
isEmptyTree :: BST -> Bool
isEmptyTree Nil = True
isEmptyTree _ = False
leftChild :: BST -> BST
leftChild Nil = Nil
leftChild (Node l k r) = l
rightChild :: BST -> BST
rightChild Nil = Nil
rightChild (Node l k r) = r
root :: BST -> Int
root Nil = error "Empty Tree"
root (Node l k r) = …Run Code Online (Sandbox Code Playgroud)