Jan-05-2020, 04:09 PM
You could use preorder, and get the len() of the list returned by preorder. If you don't want to build that whole list, you could write a method to just calculate the number of nodes:
def __len__(self): if self.is_empty(): return 0 else: return 1 + len(self.lc()) + len(self.rc())Note that by naming it __len__, it will be used by the built-in len() function, which is what I do with the calls to the children on line 5.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures