Skip to content

Commit 9b93c80

Browse files
author
Amogh Singhal
authored
Create general_tree_structure.py
1 parent 0888074 commit 9b93c80

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

general_tree_structure.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Node:
2+
def __init__(self, value=None, children=[]):
3+
self.value = value
4+
self.children = children
5+
6+
def getValue(self):
7+
return self.value
8+
9+
def setValue(self, new_value):
10+
self.value = new_value
11+
12+
def getNumChildren(self):
13+
return len(self.children)
14+
15+
def getChild(self, index):
16+
return self.children[index]
17+
18+
root = Node(5,[Node(2), Node(6)])
19+
print(root.getValue()) # 5
20+
print(root.getNumChildren()) # 2
21+
print(root.getChild(1)) # <Node object at 0x7f856fe764e0>

0 commit comments

Comments
 (0)