Created
June 6, 2023 09:44
-
-
Save lion137/dc487f18f2786eeb6961ef9516cd2019 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BinaryTree: | |
def __init__(self, root): | |
self.root = Node(root) | |
def preorder(self, root): | |
if root is None: | |
return | |
print(root.data, end=" ,") | |
self.preorder(root.left) | |
self.preorder(root.right) | |
def depth(self, node): | |
# TODO | |
pass | |
tree = BinaryTree(1) | |
tree.root.left = Node(2) | |
tree.root.right = Node(3) | |
tree.root.left.left = Node(4) | |
tree.root.left.left.left = Node(5) | |
print(tree.preorder(tree.root)) | |
print("-----") | |
print(tree.depth(tree.root)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment