summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhongheng Liu <z.liu@outlook.com.gr>2024-10-22 15:00:53 +0300
committerZhongheng Liu <z.liu@outlook.com.gr>2024-10-22 15:00:53 +0300
commit8b59e86daa1a48592c70e858636fd7f2002e8779 (patch)
treed21cae1a2b39818080b38a499c360d89e78b1171
parent714f574a0029af1fd7de0989eda28df46f5bec4f (diff)
downloadcs-y13-8b59e86daa1a48592c70e858636fd7f2002e8779.tar.gz
cs-y13-8b59e86daa1a48592c70e858636fd7f2002e8779.tar.bz2
cs-y13-8b59e86daa1a48592c70e858636fd7f2002e8779.zip
feat: make new thing
-rw-r--r--README.md2
-rw-r--r--linked.py39
2 files changed, 40 insertions, 1 deletions
diff --git a/README.md b/README.md
index e666950..c63d29a 100644
--- a/README.md
+++ b/README.md
@@ -1 +1 @@
-# cs-y13 \ No newline at end of file
+# cs-y13
diff --git a/linked.py b/linked.py
new file mode 100644
index 0000000..cd5d36e
--- /dev/null
+++ b/linked.py
@@ -0,0 +1,39 @@
+import random
+def generator(l, up, low, h):
+ linked = []
+ linkedp = []
+ for i in range(l):
+ linked.append(random.randint(up, low) if i < h else None)
+ if i == 0:
+ linkedp.append(-1)
+ continue
+ linkedp.append(i-1)
+ return (linked, linkedp, h-1, -1, h)
+# my_list = [37, 18, 49, 77, 68, None, None, None, None, None]
+# my_plist = [-1, 0, 1, 2, 3, 4, 5, 6, 7, -1]
+def delete(element, my_list, my_plist, start, null, heap):
+ #global start, heap, my_list, null
+ if start == null:
+ # empty
+ print("Linked list empty")
+ return None
+ index = start
+ oldIndex = start
+ while my_list[index] != element and index != null:
+ oldIndex = index
+ index = my_plist[index]
+ if index == null:
+ print("Item does not exist.")
+ return None
+ tmp_pointer = my_plist[index]
+ my_plist[index] = heap
+ heap = index
+ my_plist[oldIndex] = tmp_pointer
+LENGTH = 15
+l,p,s,n,h = generator(LENGTH, 0, 100, round(LENGTH / 2))
+for i in range(len(l)):
+ print(f"[{i}]\t{l[i]}\t{p[i]}\t{'<- heap' if i == h else ''}")
+print("-------")
+delete(int(input("$ ")), l, p, s, n, h)
+for i in range(len(l)):
+ print(f"[{i}]\t{l[i]}\t{p[i]}\t{'<- heap' if i == h else ''}")