MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / __len__

Method __len__

data_structures/binary_tree/red_black_tree.py:455–464  ·  view source on GitHub ↗

Return the number of nodes in this tree.

(self)

Source from the content-addressed store, hash-verified

453 return True
454
455 def __len__(self) -> int:
456 """
457 Return the number of nodes in this tree.
458 """
459 ln = 1
460 if self.left:
461 ln += len(self.left)
462 if self.right:
463 ln += len(self.right)
464 return ln
465
466 def preorder_traverse(self) -> Iterator[int | None]:
467 yield self.label

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected