Data structures 检查是否平衡二叉树(标准ml)

Data structures 检查是否平衡二叉树(标准ml),data-structures,tree,functional-programming,sml,ml,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 令人难过的是,你甚至

树数据类型为:

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

令人难过的是,你甚至没有费心去寻找答案,因为SO:S已经有一个答案了。它一定是在时间上接近手了?可能是重复的