标签:ldl bool div node int 结构 树形结构 empty als
data Tree = Node Int Tree Tree | Empty
insert :: Tree -> Int -> Tree
insert Empty a = (Node a Empty Empty)
insert (Node p lson rson) a
| p > a = Node p lson (insert rson a)
| p == a = Node p lson rson
| otherwise = Node p (insert lson a) rson
find :: Tree -> Int -> Bool
find Empty a = False
find (Node p lson rson) a
| p > a = find rson a
| p == a = True
| otherwise = find lson a
toTree :: [Int] -> Tree
toTree = foldl insert Empty
main = do
let tree = toTree [10,123,-1,5435,143]
if(find tree 250)
then putStrLn "Yes"
else putStrLn "No"
ps : haskell 写树形结构真的短。。。。。
标签:ldl bool div node int 结构 树形结构 empty als
原文地址:http://www.cnblogs.com/HC-LittleJian/p/7903588.html