summaryrefslogtreecommitdiff
path: root/recursive_node.py
diff options
context:
space:
mode:
Diffstat (limited to 'recursive_node.py')
-rw-r--r--recursive_node.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/recursive_node.py b/recursive_node.py
new file mode 100644
index 0000000..22bc75d
--- /dev/null
+++ b/recursive_node.py
@@ -0,0 +1,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)