davegimo

vanessa_lezione_4

Apr 26th, 2022
801
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. def A_Ex4(a,n):
  2.     conta = contanodi(a,n,0)
  3.     return conta
  4.  
  5. def contanodi(a,n,livellocorrente):
  6.  
  7.     if a is None:
  8.         return 0
  9.  
  10.     if livellocorrente == n:
  11.         return 1
  12.  
  13.     if a.getLeftChild() is None and a.getRightChild() is None:
  14.         return 0
  15.  
  16.  
  17.     conta = 0
  18.  
  19.     if a.getLeftChild() is not None:
  20.         conta += contanodi(a.getLeftChild(),n,livellocorrente + 1)
  21.  
  22.     if a.getRightChild() is not None:
  23.         conta += contanodi(a.getRightChild(),n,livellocorrente + 1)
  24.  
  25.  
  26.     return conta
  27.    
  28.    
  29.        
Advertisement
Add Comment
Please, Sign In to add comment