From 538ad691be38618ae39bd5093b8608ea34f08684 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Sat, 23 Mar 2013 21:05:20 +0100 Subject: Improvement to the binarytree implementation: the root is now given to the __init__ function. --- source/testbinarytree.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'source/testbinarytree.py') 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 -- cgit