blob: 22bc75dee4a8c91cebf5bc22de00fa8ed89f4132 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
import numpy as np
class Node():
"""
@todo: docstring for Node
"""
def __init__(self, value=None):
"""@todo: Docstring for init method.
/value=None/ @todo
"""
self.value = value
def add_split(self, left, right):
"""
@todo: Docstring for add_split
"""
self.left = left
self.right = right
class Tree():
"""
@todo: docstring for Tree
"""
def __init__(self, root_node_obj):
"""@todo: Docstring for init method.
/root_node_obj/ @todo
"""
self.tree = root_node_obj
def __repr__(self):
nodelist = [self.tree]
tree_str = ''
while nodelist:
current_node = nodelist.pop()
# print(current_node.value)
try:
childs = [current_node.right, current_node.left]
nodelist += childs
except AttributeError:
pass
tree_str += current_node.value
return tree_str
n1 = Node(value="root\n")
n2 = Node(value="left child of n1, ")
n3 = Node(value="right child of n1")
n1.add_split(n2, n3)
my_tree = Tree(n1)
print(my_tree)
|