mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-12-18 01:00:15 +00:00
fix: code review changes
This commit is contained in:
parent
31bc93f1a2
commit
7e010687c4
|
@ -12,12 +12,9 @@ class TreeNode:
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
-----------
|
-----------
|
||||||
value : int
|
value : The value stored at the node.
|
||||||
The value stored at the node.
|
left : Pointer to the left child node (default is None).
|
||||||
left : TreeNode
|
right : Pointer to the right child node (default is None).
|
||||||
Pointer to the left child node (default is None).
|
|
||||||
right : TreeNode
|
|
||||||
Pointer to the right child node (default is None).
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, value: int) -> None:
|
def __init__(self, value: int) -> None:
|
||||||
|
@ -30,15 +27,6 @@ class BinaryTree:
|
||||||
"""
|
"""
|
||||||
Class representing a binary tree.
|
Class representing a binary tree.
|
||||||
|
|
||||||
Methods:
|
|
||||||
--------
|
|
||||||
insert(value: int) -> None:
|
|
||||||
Insert a value into the binary tree following binary search tree (BST) rules.
|
|
||||||
|
|
||||||
morris_postorder_traversal() -> List[int]:
|
|
||||||
Perform postorder traversal and return list of node values.
|
|
||||||
|
|
||||||
|
|
||||||
>>> bt = BinaryTree()
|
>>> bt = BinaryTree()
|
||||||
>>> bt.insert(9)
|
>>> bt.insert(9)
|
||||||
>>> bt.insert(6)
|
>>> bt.insert(6)
|
||||||
|
@ -63,8 +51,7 @@ class BinaryTree:
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
-----------
|
-----------
|
||||||
value : int
|
value : The value to be inserted into the binary tree.
|
||||||
The value to be inserted into the binary tree.
|
|
||||||
"""
|
"""
|
||||||
if self.root is None:
|
if self.root is None:
|
||||||
self.root = TreeNode(value)
|
self.root = TreeNode(value)
|
||||||
|
@ -77,10 +64,8 @@ class BinaryTree:
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
-----------
|
-----------
|
||||||
node : TreeNode
|
node : The current node in the binary tree.
|
||||||
The current node in the binary tree.
|
value : The value to be inserted.
|
||||||
value : int
|
|
||||||
The value to be inserted.
|
|
||||||
"""
|
"""
|
||||||
if value < node.value:
|
if value < node.value:
|
||||||
if node.left is None:
|
if node.left is None:
|
||||||
|
@ -98,13 +83,11 @@ class BinaryTree:
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
-----------
|
-----------
|
||||||
node : TreeNode
|
node : A node in the binary tree.
|
||||||
A node in the binary tree.
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
--------
|
--------
|
||||||
TreeNode:
|
The successor of the node passed in the parameter
|
||||||
The successor of the node passed in the parameter
|
|
||||||
"""
|
"""
|
||||||
temp_node = node.right
|
temp_node = node.right
|
||||||
while temp_node and temp_node.left and temp_node.left != node:
|
while temp_node and temp_node.left and temp_node.left != node:
|
||||||
|
@ -139,8 +122,7 @@ class BinaryTree:
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
--------
|
--------
|
||||||
List[int]:
|
A list of integers representing the postorder traversal.
|
||||||
A list of integers representing the postorder traversal.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user