aboutsummaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/binarytree.py7
-rw-r--r--source/testbinarytree.py15
2 files changed, 12 insertions, 10 deletions
diff --git a/source/binarytree.py b/source/binarytree.py
index 52e32db7..c9747d57 100644
--- a/source/binarytree.py
+++ b/source/binarytree.py
@@ -21,11 +21,11 @@ class OrderedBinaryTree(object):
"""
Represents a binary ordered .
"""
- def __init__(self):
+ def __init__(self, root):
"""
Initializes the root member.
"""
- self.root = None
+ self.root = root
def addNode(self, data):
"""
@@ -147,7 +147,8 @@ class OrderedBinaryTree(object):
"""
Pretty display.
"""
- return ", ".join([article["article_title"] for article in self.in_order_traversal(self.root)])
+ return ", ".join([article["article_title"] for article in \
+ self.in_order_traversal(self.root)])
if __name__ == "__main__":
# Point of entry in execution mode.
diff --git a/source/testbinarytree.py b/source/testbinarytree.py
index 7694ad4e..67b19368 100644
--- a/source/testbinarytree.py
+++ b/source/testbinarytree.py
@@ -22,22 +22,23 @@ print(("{} articles loaded in {} seconds.".format(len(articles), end-begin)))
print("Generating the binary tree...")
begin = time.time()
-tree = binarytree.OrderedBinaryTree()
+root = binarytree.Node(articles[0])
+tree = binarytree.OrderedBinaryTree(root)
# add the root node (first article of the list)
-root = tree.addNode(articles[0])
+#root = tree.addNode(articles[0])
for article in articles[1:]:
- tree.insert(root, article)
+ tree.insert(tree.root, article)
end = time.time()
print(("Generation done in {0:2f} seconds.".format(end-begin)))
print("Maximum depth of the tree:")
-print(tree.maxDepth(root))
+print(tree.maxDepth(tree.root))
print("Oldest article:")
-oldest_article = tree.minValue(root)
+oldest_article = tree.minValue(tree.root)
print((oldest_article["article_date"].strftime('%Y-%m-%d %H:%M') + \
" - " + oldest_article["article_title"]))
print("Newest article:")
-newest_article = tree.maxValue(root)
+newest_article = tree.maxValue(tree.root)
print((newest_article["article_date"].strftime('%Y-%m-%d %H:%M') + \
" - " + newest_article["article_title"]))
-print(tree)
+print(tree) \ No newline at end of file
bgstack15