summaryrefslogtreecommitdiff
path: root/lesson4.py
diff options
context:
space:
mode:
authorZhongheng Liu <z.liu@outlook.com.gr>2024-10-15 15:02:59 +0300
committerZhongheng Liu <z.liu@outlook.com.gr>2024-10-15 15:02:59 +0300
commit714f574a0029af1fd7de0989eda28df46f5bec4f (patch)
tree8606fd0eaa357450e3bb248e3550bf9cc617ea61 /lesson4.py
parent99fcc543354860ed485b6ded092db4229adcaa16 (diff)
downloadcs-y13-714f574a0029af1fd7de0989eda28df46f5bec4f.tar.gz
cs-y13-714f574a0029af1fd7de0989eda28df46f5bec4f.tar.bz2
cs-y13-714f574a0029af1fd7de0989eda28df46f5bec4f.zip
feat: cs lesson 4 material
Diffstat (limited to 'lesson4.py')
-rw-r--r--lesson4.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/lesson4.py b/lesson4.py
new file mode 100644
index 0000000..e99f231
--- /dev/null
+++ b/lesson4.py
@@ -0,0 +1,37 @@
+stack = [None for index in range(0,10)]
+basePointer = 0
+topPointer = -1
+stackFull = 10
+
+def push(item):
+ global stack, topPointer
+ topPointer += 1
+ if topPointer >= stackFull:
+ print("ERROR Cannot insert more.")
+ return
+ stack[topPointer] = item
+ print(stack)
+def pop():
+ global stack, topPointer
+ if topPointer < basePointer:
+ print("ERROR List is empty, cannot pop.")
+ return
+ itemPopped = stack[topPointer]
+ print(f"I popped this {itemPopped}")
+ stack[topPointer] = None
+ topPointer -= 1
+ print(stack)
+def test():
+ push(1)
+ push(2)
+ push(69)
+
+ pop()
+ pop()
+
+ print(stack)
+
+ pop()
+ pop()
+
+test()