加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Codetest3

发布时间:2020-12-14 04:46:42 所属栏目:大数据 来源:网络整理
导读:def depth_of_tree (tree): #This is the recursive function to find the depth of binary tree. if tree is None : return 0 else : depth_l_tree = depth_of_tree(tree.left) depth_r_tree = depth_of_tree(tree.right) if depth_l_tree depth_r_tree: re

def depth_of_tree(tree): #This is the recursive function to find the depth of binary tree.
if tree is None:
return 0
else:
depth_l_tree = depth_of_tree(tree.left)
depth_r_tree = depth_of_tree(tree.right)
if depth_l_tree > depth_r_tree:
return 1 + depth_l_tree
else:
return 1 + depth_r_tree

?

?



def depth_of_tree(tree):?#This is the recursive function to find the depth of binary tree.
????if tree is?None:
????????return?0
????else:
????????depth_l_tree = depth_of_tree(tree.left)
????????depth_r_tree = depth_of_tree(tree.right)
????????if depth_l_tree > depth_r_tree:
????????????return?1?+ depth_l_tree
????????else:
????????????return?1?+ depth_r_tree

?

  1. def display(tree): #In Order traversal of the tree 
  2. ?
  3.  if tree is None:  
  4.  return 
  5. ?
  6.  if tree.left is not None: 
  7.  display(tree.left) 
  8. ?
  9.  print(tree.data) 
  10. ?
  11.  if tree.right is not None: 
  12.  display(tree.right) 
  13. ?
  14.  return 
  15. ?

?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读