summaryrefslogtreecommitdiff
path: root/hw/activity20h.py
diff options
context:
space:
mode:
authorZhongheng Liu <z.liu@outlook.com.gr>2025-02-18 11:58:46 +0200
committerZhongheng Liu <z.liu@outlook.com.gr>2025-02-18 11:58:46 +0200
commit34bd7099d27656b4454015b0c410ca1713db5271 (patch)
treeb2705e345e490932c7f6284b056549c6a3963cc4 /hw/activity20h.py
parent5e297261b05ed2c3feef0a892fc47e5fa06dbc4c (diff)
downloadcs-y13-34bd7099d27656b4454015b0c410ca1713db5271.tar.gz
cs-y13-34bd7099d27656b4454015b0c410ca1713db5271.tar.bz2
cs-y13-34bd7099d27656b4454015b0c410ca1713db5271.zip
feat: add activity 20h
Diffstat (limited to 'hw/activity20h.py')
-rw-r--r--hw/activity20h.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/hw/activity20h.py b/hw/activity20h.py
new file mode 100644
index 0000000..8bf0319
--- /dev/null
+++ b/hw/activity20h.py
@@ -0,0 +1,28 @@
+class TreeNode:
+ def __init__(self, value):
+ self.value = value
+ self.left = None
+ self.right = None
+ def insert(self, v):
+ left = True if v < self.value else False
+ if left:
+ print(f"Inserting to the left because {v} < self value = {self.value}")
+ if self.left != None:
+ self.left.insert(v)
+ else:
+ self.left = TreeNode(v)
+ else:
+ print(f"Inserting to the right because {v} >= self value = {self.value}")
+ if self.right != None:
+ self.right.insert(v)
+ else:
+ self.right = TreeNode(v)
+class Tree:
+ def __init__(self, root_value):
+ self.root = TreeNode(root_value)
+ def insert(self, v):
+ self.root.insert(v)
+t = Tree(27)
+l = [19, 36, 42, 16]
+for i in l:
+ t.insert(i)