Resolve --mypy-- errors

pull/1140/head
santhoshtk 2023-01-13 18:19:53 +05:30
parent 7a00d45642
commit fe68d4d12b
1 changed files with 12 additions and 12 deletions

View File

@ -29,7 +29,7 @@ class BinaryTree:
- root (BinaryTreeNode) : The root of the Binary Tree. - root (BinaryTreeNode) : The root of the Binary Tree.
""" """
def __init__(self): def __init__(self):
self.root: Optional[BinaryTreeNode] = None self.root = None
def insert(self, value: int) -> str: def insert(self, value: int) -> str:
""" """
@ -46,7 +46,7 @@ class BinaryTree:
self.root = BinaryTreeNode(value) self.root = BinaryTreeNode(value)
else: else:
# Creating the FIFO (Queue) for level order traversal # Creating the FIFO (Queue) for level order traversal
auxQueue = Queue() auxQueue: Queue = Queue()
auxQueue.put(self.root) auxQueue.put(self.root)
while not auxQueue.empty(): while not auxQueue.empty():
@ -70,9 +70,9 @@ class BinaryTree:
class RecursiveTraversal: class RecursiveTraversal:
"""Class to represent Recursive Traversals of the Binary Tree.""" """Class to represent Recursive Traversals of the Binary Tree."""
def preOrder(self, root: BinaryTreeNode, result: list) -> Union[None, list]: def preOrder(self, root, result: list) -> Union[None, list]:
if not root: if not root:
return return None
else: else:
result.append(root.data) result.append(root.data)
self.preOrder(root.leftChild, result) self.preOrder(root.leftChild, result)
@ -80,9 +80,9 @@ class RecursiveTraversal:
return result return result
def inOrder(self, root: BinaryTreeNode, result: list) -> Union[None, list]: def inOrder(self, root, result: list) -> Union[None, list]:
if not root: if not root:
return return None
else: else:
self.inOrder(root.leftChild, result) self.inOrder(root.leftChild, result)
result.append(root.data) result.append(root.data)
@ -90,9 +90,9 @@ class RecursiveTraversal:
return result return result
def postOrder(self, root: BinaryTreeNode, result: list) -> Union[None, list]: def postOrder(self, root, result: list) -> Union[None, list]:
if not root: if not root:
return return None
else: else:
self.postOrder(root.leftChild, result) self.postOrder(root.leftChild, result)
self.postOrder(root.rightChild, result) self.postOrder(root.rightChild, result)
@ -110,7 +110,7 @@ class IterativeTraversal(BinaryTree):
if not self.root: if not self.root:
return "The Binary Tree is Empty." return "The Binary Tree is Empty."
else: else:
auxStack = LifoQueue() auxStack: LifoQueue = LifoQueue()
auxStack.put(self.root) auxStack.put(self.root)
while not auxStack.empty(): while not auxStack.empty():
@ -132,7 +132,7 @@ class IterativeTraversal(BinaryTree):
if not self.root: if not self.root:
return "The Binary Tree is Empty." return "The Binary Tree is Empty."
else: else:
auxStack = LifoQueue() auxStack: LifoQueue = LifoQueue()
currentNode = self.root currentNode = self.root
while currentNode or not auxStack.empty(): while currentNode or not auxStack.empty():
@ -154,8 +154,8 @@ class IterativeTraversal(BinaryTree):
if not self.root: if not self.root:
return "The Binary Tree is Empty." return "The Binary Tree is Empty."
else: else:
auxStack = [] auxStack: list = []
previous: Optional[BinaryTreeNode] = None previous: BinaryTreeNode
currentNode = self.root currentNode = self.root
while currentNode or auxStack: while currentNode or auxStack: