Skip to content

Commit 8c3783a

Browse files
committed
fix: code review changes
1 parent e667b8a commit 8c3783a

File tree

1 file changed

+9
-27
lines changed

1 file changed

+9
-27
lines changed

data_structures/binary_tree/morris_preorder_traversal.py

+9-27
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,9 @@ class TreeNode:
1212
1313
Attributes:
1414
-----------
15-
value : int
16-
The value stored at the node.
17-
left : TreeNode
18-
Pointer to the left child node (default is None).
19-
right : TreeNode
20-
Pointer to the right child node (default is None).
15+
value : The value stored at the node.
16+
left : Pointer to the left child node (default is None).
17+
right : Pointer to the right child node (default is None).
2118
"""
2219

2320
def __init__(self, value: int) -> None:
@@ -30,15 +27,6 @@ class BinaryTree:
3027
"""
3128
Class representing a binary tree.
3229
33-
Methods:
34-
--------
35-
insert(value: int) -> None:
36-
Insert a value into the binary tree following binary search tree (BST) rules.
37-
38-
morris_preorder_traversal() -> List[int]:
39-
Perform preorder traversal and return list of node values.
40-
41-
4230
>>> bt = BinaryTree()
4331
>>> bt.insert(9)
4432
>>> bt.insert(6)
@@ -63,8 +51,7 @@ def insert(self, value: int) -> None:
6351
6452
Parameters:
6553
-----------
66-
value : int
67-
The value to be inserted into the binary tree.
54+
value : The value to be inserted into the binary tree.
6855
"""
6956
if self.root is None:
7057
self.root = TreeNode(value)
@@ -77,10 +64,8 @@ def _insert_recursive(self, node: TreeNode, value: int) -> None:
7764
7865
Parameters:
7966
-----------
80-
node : TreeNode
81-
The current node in the binary tree.
82-
value : int
83-
The value to be inserted.
67+
node : The current node in the binary tree.
68+
value : The value to be inserted.
8469
"""
8570
if value < node.value:
8671
if node.left is None:
@@ -98,13 +83,11 @@ def _predecessor(self, node: TreeNode) -> TreeNode:
9883
9984
Parameters:
10085
-----------
101-
node : TreeNode
102-
A node in the binary tree.
86+
node : A node in the binary tree.
10387
10488
Returns:
10589
--------
106-
TreeNode:
107-
The predecessor of the node passed in the parameter
90+
The predecessor of the node passed in the parameter
10891
"""
10992
temp_node = node.left
11093
while temp_node and temp_node.right and temp_node.right != node:
@@ -137,8 +120,7 @@ def morris_preorder_traversal(self) -> list[int]:
137120
138121
Returns:
139122
--------
140-
List[int]:
141-
A list of integers representing the preorder traversal.
123+
A list of integers representing the preorder traversal.
142124
143125
144126

0 commit comments

Comments
 (0)