Codetest3

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.  

 

posted @ 2019-05-20 23:51  binyang  阅读(111)  评论(0编辑  收藏  举报