@@ -13,7 +13,13 @@ class TreeNode(Generic[T]):
1313 """
1414
1515 def __init__ (
16- self , value : T , key : Optional [Any ] = None , parent : Optional ["TreeNode" ] = None
16+ self ,
17+ value : T ,
18+ key : Optional [Any ] = None ,
19+ parent : Optional ["TreeNode" ] = None ,
20+ depth : Optional [int ] = None ,
21+ height : Optional [int ] = None ,
22+ degree : Optional [int ] = None ,
1723 ):
1824 """
1925 Initialises a tree node with a value, key and a parent node.
@@ -23,16 +29,22 @@ def __init__(
2329 value (T): The value of the node
2430 key (Optional[Any]): The key of the node. If not provided, a hash of the data is used.
2531 parent (Optional[TreeNode]): The parent node of the current node.
32+ depth (int): The depth of the current node.
33+ height (int): The height of the current node.
34+ degree (int): The degree of the current node.
2635
2736 Notes:
2837 The key is used to identify the node in the tree. If not key is provided, a hash of the data is used.
2938 """
3039 self .data = value
3140 self .key = key or hash (value )
3241 self .parent = parent
42+ self .depth = depth
43+ self .height = height
44+ self .degree = degree
3345
3446 def __repr__ (self ):
35- return f"TreeNode(data={ self .data } , key={ self .key } )"
47+ return f"TreeNode(data={ self .data } , key={ self .key } , depth= { self . depth } , height= { self . height } , degree= { self . degree } )"
3648
3749 def __eq__ (self , other : "TreeNode[T]" ) -> bool :
3850 """Checks if this node is equal to another node based on the data they contain
0 commit comments