您的位置:首页 > 其它

F# 树

2016-04-08 20:12 267 查看
树1

> type BinTree<'a, 'b> =
| Leaf of 'a
| Node of BinTree<'a, 'b> * 'b * BinTree<'a, 'b>;;

type BinTree<'a,'b> =
| Leaf of 'a
| Node of BinTree<'a,'b> * 'b * BinTree<'a,'b>

> let t1 = Node(Node(Leaf 1, "cd", Leaf 2), "ab", Leaf 3);;

val t1 : BinTree<int,string> = Node (Node (Leaf 1,"cd",Leaf 2),"ab",Leaf 3)

> let rec depth = function
| Leaf _ -> 0
| Node (t1, _, t2) -> 1 + max (depth t1) (depth t2);;

val depth : _arg1:BinTree<'a,'b> -> int

> depth t1;;
val it : int = 2
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: