diff options
-rw-r--r-- | notebooks/data_structures.ipynb | 11 | ||||
-rw-r--r-- | notebooks/dictionaries.ipynb | 40 | ||||
-rw-r--r-- | notebooks/linked_lists.ipynb | 98 |
3 files changed, 148 insertions, 1 deletions
diff --git a/notebooks/data_structures.ipynb b/notebooks/data_structures.ipynb index f116cf5..370c569 100644 --- a/notebooks/data_structures.ipynb +++ b/notebooks/data_structures.ipynb @@ -5,7 +5,8 @@ "metadata": {}, "source": [ "# ADT - Stack\n", - "Push and pop methods." + "Push and pop methods. \n", + "Primitively, we consider the stack and queue ADTs with a simple array. \n" ] }, { @@ -112,7 +113,15 @@ "name": "python3" }, "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", "version": "3.12.8" } }, diff --git a/notebooks/dictionaries.ipynb b/notebooks/dictionaries.ipynb index e69de29..dabcc4f 100644 --- a/notebooks/dictionaries.ipynb +++ b/notebooks/dictionaries.ipynb @@ -0,0 +1,40 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Activity 19P\n", + "\n", + "TEST_CLASS_EXAM_DATA = {\n", + " \"Justin\": 0,\n", + " \"Kim Jong Un\": 69,\n", + " \"Kim Il-Sung\": 150,\n", + "}\n", + "\n", + "print(TEST_CLASS_EXAM_DATA[\"Justin\"])\n", + "\n", + "TEST_CLASS_EXAM_DATA[\"Skibidi Rizzler\"] = 66\n", + "\n", + "del TEST_CLASS_EXAM_DATA[\"Justin\"]\n", + "\n", + "print(TEST_CLASS_EXAM_DATA)\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": ".venv", + "language": "python", + "name": "python3" + }, + "language_info": { + "name": "python", + "version": "3.12.8" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/notebooks/linked_lists.ipynb b/notebooks/linked_lists.ipynb index e69de29..5f11e96 100644 --- a/notebooks/linked_lists.ipynb +++ b/notebooks/linked_lists.ipynb @@ -0,0 +1,98 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0] None\t1\t\t<- free pointer\n", + "[1] None\t2\t\t\n", + "[2] None\t3\t\t\n", + "[3] None\t4\t\t\n", + "[4] None\t5\t\t\n", + "[5] None\t6\t\t\n", + "[6] None\t7\t\t\n", + "[7] None\t8\t\t\n", + "[8] None\t9\t\t\n", + "[9] None\t-1\t\t\n", + "=========\n", + "[0] Steven\t-1\t\t\n", + "[1] Xi Jinping\t0\t\t\n", + "[2] Deng Xiaoping\t1\t\t\n", + "[3] Chiang Kai-shek\t2\t\t\n", + "[4] Donald Trump\t3\t<- root pointer\t\n", + "[5] None\t6\t\t<- free pointer\n", + "[6] None\t7\t\t\n", + "[7] None\t8\t\t\n", + "[8] None\t9\t\t\n", + "[9] None\t-1\t\t\n", + "=========\n" + ] + } + ], + "source": [ + "class LinkedList:\n", + " def __init__(self, l):\n", + " self.list = []\n", + " self.rootp = -1\n", + " self.freep = 0\n", + " for i in range(l):\n", + " self.list.append([None, i+1])\n", + " self.list[l-1][1] = -1\n", + " self.visualise()\n", + " def visualise(self):\n", + " i = 0\n", + " while i < len(self.list):\n", + " print(f\"[{i}] {self.list[i][0]}\\t{self.list[i][1]}\\t{'<- root pointer' if self.rootp == i else ''}\\t{'<- free pointer' if self.freep == i else ''}\")\n", + " i += 1\n", + " print(\"=========\")\n", + " def insert(self, elem): \n", + " if self.freep == -1:\n", + " print(\"Unable, not free!\")\n", + " self.list[self.freep][0] = elem \n", + " tmp = self.list[self.freep][1]\n", + " self.list[self.freep][1] = self.rootp \n", + " self.rootp = self.freep\n", + " self.freep = tmp\n", + " #self.visualise()\n", + "new_list = LinkedList(10)\n", + "names = [\n", + " \"Steven\",\n", + " \"Xi Jinping\",\n", + " \"Deng Xiaoping\",\n", + " \"Chiang Kai-shek\",\n", + " \"Donald Trump\"\n", + "]\n", + "for name in names:\n", + " new_list.insert(name)\n", + "new_list.visualise()\n", + "\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": ".venv", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.8" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} |