python 怎样返回一个树中正好有两个子节点的节点数量?
classRefBinaryTree:def__init__(self,data,left=None,right=None):self.key=dataself.left...
class RefBinaryTree:
def __init__(self,data,left=None,right=None):
self.key = data
self.left = left
self.right = right
def get_number_with_2child(self):
pass
def get_left_subtree(self):
return self.left
def get_right_subtree(self):
return self.right
def get_value(self):
return self.key 展开
def __init__(self,data,left=None,right=None):
self.key = data
self.left = left
self.right = right
def get_number_with_2child(self):
pass
def get_left_subtree(self):
return self.left
def get_right_subtree(self):
return self.right
def get_value(self):
return self.key 展开
1个回答
展开全部
def get_number_with_2child(self):
if self.left and self.right:
return 1+self.left.get_number_with_2child()+self.right.get_number_with_2child()
elif self.left:
return self.left.get_number_with_2child()
elif self.rught:
return self.right.get_number_with_2child()
else:
return 0
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询