Created
November 19, 2021 11:07
-
-
Save kelvingakuo/d9deb1b9ef1dad1b30a3cecf36ff2fe5 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 Node(object): | |
def __init__(self, val): | |
self.value = val # Value of node | |
self.children = [] # Can have multiple children | |
def add_child(self, node): | |
self.children.append(node) | |
return node | |
# Usage | |
tree = Node("root") | |
f_child = tree.add_child(Node("first_child")) | |
s_child = tree.add_child(Node("second_child")) | |
t_child = tree.add_child(Node("third_child")) | |
ff_child = f_child.add_child(Node("first_first_child")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment