-
Notifications
You must be signed in to change notification settings - Fork 0
Trees usage
Alex Mytnyk edited this page Jun 5, 2022
·
4 revisions
Every implemented tree inherits AbstractTree class. That means you can use every method declared in AbstractTree, e.g get, contains, insert, delete, __iter__
Example:
from core.trees.red_black_tree import RedBlackTree
population_tree = RedBlackTree()
population_tree["Lviv"] = 1000000
population_tree["Kyiv"] = 2900000
population_tree["Dnipro"] = 870000
print(population_tree["Kyiv"])
# 2900000
print("Lviv" in population_tree)
# True
print("Kharkiv" in population_tree)
# False
population_tree.delete("Dnipro")
print("Dnipro" in population_tree)
# False
print(list(population_tree))
# [('Kyiv', 2900000), ('Lviv', 1000000)]