Guest User

Untitled

a guest
Dec 3rd, 2019
75
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def level(self, level):
  2. if level == 0 or self.value() == None:
  3. return [self.value()]
  4. else:
  5. return self.lc().level(level-1) + self.rc().level(level-1)
  6.  
  7.  
  8.  
  9. def bfs_order_star(self):
  10. '''
  11. Returns a list of all members in breadth-first search* order, which
  12. means that empty nodes are denoted by "stars" (here the value None).
  13.  
  14. For example, consider the following tree `t`:
  15. 10
  16. 5 15
  17. * * * 20
  18.  
  19. The output of t.bfs_order_star() should be:
  20. [ 10, 5, 15, None, None, None, 20 ]
  21. '''
  22. h=self.height()
  23. arr=[]
  24. for i in range(h):
  25. arr=arr+self.level(i)
  26. return arr
RAW Paste Data