Skip to content

adding static type checking to basic_binary_tree.py #2293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 11, 2020
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions data_structures/binary_tree/basic_binary_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ class Node:
and left, right pointers.
"""

def __init__(self, data):
def __init__(self, data: int) -> None:
self.data = data
self.left = None
self.right = None
self.left: Optional[Node] = None
self.right: Optional[Node] = None


def display(tree): # In Order traversal of the tree
def display(tree: Node) -> None: # In Order traversal of the tree

if tree is None:
return
Expand All @@ -26,9 +26,11 @@ def display(tree): # In Order traversal of the tree
return


def depth_of_tree(
tree,
): # This is the recursive function to find the depth of binary tree.
def depth_of_tree(tree: Node,) -> int:
"""
Recursive function that finds the depth of a binary tree.
"""

if tree is None:
return 0
else:
Expand All @@ -40,9 +42,11 @@ def depth_of_tree(
return 1 + depth_r_tree


def is_full_binary_tree(
tree,
): # This function returns that is it full binary tree or not?
def is_full_binary_tree(tree: Node,) -> bool:
"""
Returns True if this is a full binary tree
"""

if tree is None:
return True
if (tree.left is None) and (tree.right is None):
Expand All @@ -53,7 +57,7 @@ def is_full_binary_tree(
return False


def main(): # Main function for testing.
def main() -> None: # Main function for testing.
tree = Node(1)
tree.left = Node(2)
tree.right = Node(3)
Expand Down