检查平衡二叉树(标准ml)

时间:2013-01-18 00:20:27

标签: data-structures tree functional-programming sml ml

树数据类型为:

datatype mobile = Object of int | Wire of mobile * mobile

要检查它是否平衡我发现我必须先做一个权重函数来计算每个节点的值的权重,然后比较左子树和右树。但是我很难用ml语言。

到目前为止

代码:

fun balanced  Object = true
if(weight(Wire(x,t1)) - weight(Wire(y,t1))) = 0)
   then true
else false

0 个答案:

没有答案
相关问题