F# 树

来源:互联网 发布:mac怎么分区移动硬盘pc 编辑:程序博客网 时间:2024/05/16 11:11

树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
0 0
原创粉丝点击