From 71528450b9578c6f28d2f9421c7d09bf0e4be978 Mon Sep 17 00:00:00 2001 From: WazedKhan Date: Wed, 4 Oct 2023 00:37:11 +0600 Subject: [PATCH 1/7] generate link list --- DSA/Linked_List/self_referential.py | 52 +++++++++++++++++++++ re_leet_code/merge_two_sorted_lists/main.py | 9 ++++ 2 files changed, 61 insertions(+) create mode 100644 DSA/Linked_List/self_referential.py create mode 100644 re_leet_code/merge_two_sorted_lists/main.py diff --git a/DSA/Linked_List/self_referential.py b/DSA/Linked_List/self_referential.py new file mode 100644 index 0000000..426c6a2 --- /dev/null +++ b/DSA/Linked_List/self_referential.py @@ -0,0 +1,52 @@ +""" +Implementation of LinkedList Data structure in Python +""" + + +# Node class +class Node: + + # Function to initialize the node object + def __init__(self, data): + self.data = data # Assign data + self.next = None # Initialize next as null + + +# Linked List class + + +class LinkedList: + + # Function to initialize the Linked List object + def __init__(self): + self.head = None + + # function insert a new node at the beginning + def push(self, data): + # 1 & 2: allocate the Node and put in the data + new_node = Node(data=data) + + # 3. Make next of new Node as head + new_node.next = self.head + + # 4. Move the head to point to new Node + self.head = new_node + + +# Create a new linked list +my_linked_list = LinkedList() + +# Test the push method to insert nodes at the beginning +my_linked_list.push(1) +my_linked_list.push(2) +my_linked_list.push(3) + +# Print the linked list to verify the insertions +# It should print: 3 -> 2 -> 1 +current_node = my_linked_list.head +while current_node: + print(current_node.data, end=" -> ") + current_node = current_node.next +print("None") + +# You can also add more test cases to test other methods you might implement diff --git a/re_leet_code/merge_two_sorted_lists/main.py b/re_leet_code/merge_two_sorted_lists/main.py new file mode 100644 index 0000000..f69ca32 --- /dev/null +++ b/re_leet_code/merge_two_sorted_lists/main.py @@ -0,0 +1,9 @@ +def mergeTwoLists(list1, list2): + list3 = list1 + list2 + return sorted(list3) + + +list1 = [1, 2, 4] +list2 = [1, 3, 4] + +print(mergeTwoLists(list1, list2)) From 0ebd5948d7cf4532c695db7cc8df6812e0366ce7 Mon Sep 17 00:00:00 2001 From: WazedKhan Date: Tue, 10 Oct 2023 07:51:02 +0600 Subject: [PATCH 2/7] linked list 001 --- DSA/Linked_List/self_referential.py | 1 + 1 file changed, 1 insertion(+) diff --git a/DSA/Linked_List/self_referential.py b/DSA/Linked_List/self_referential.py index 426c6a2..0750143 100644 --- a/DSA/Linked_List/self_referential.py +++ b/DSA/Linked_List/self_referential.py @@ -43,6 +43,7 @@ def push(self, data): # Print the linked list to verify the insertions # It should print: 3 -> 2 -> 1 + current_node = my_linked_list.head while current_node: print(current_node.data, end=" -> ") From a99fd4d43cac6d9b3a35c40d9bfdffb7f351841c Mon Sep 17 00:00:00 2001 From: WazedKhan Date: Tue, 31 Oct 2023 22:06:20 +0600 Subject: [PATCH 3/7] linked list class --- DSA/Linked_List/define.ipynb | 43 +++++++++++++++++++++++ DSA/Linked_List/doughnut.py | 28 +++++++++++++++ DSA/Linked_List/self_referential.py | 53 ----------------------------- 3 files changed, 71 insertions(+), 53 deletions(-) create mode 100644 DSA/Linked_List/define.ipynb create mode 100644 DSA/Linked_List/doughnut.py delete mode 100644 DSA/Linked_List/self_referential.py diff --git a/DSA/Linked_List/define.ipynb b/DSA/Linked_List/define.ipynb new file mode 100644 index 0000000..5fd5183 --- /dev/null +++ b/DSA/Linked_List/define.ipynb @@ -0,0 +1,43 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "class LinkedList:\n", + " def __init__(self):\n", + " self.head = None" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.10.4" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/DSA/Linked_List/doughnut.py b/DSA/Linked_List/doughnut.py new file mode 100644 index 0000000..5a7e998 --- /dev/null +++ b/DSA/Linked_List/doughnut.py @@ -0,0 +1,28 @@ +while ('o_' in dir()) or (A := (0) + ) or (B := 0) or print(( + "\x1b[2J")) or not ((sin := (( + __import__('math'))).sin)) or not ( + cos := __import__('math').cos) or (o_ := ( + True)): [pr() for b in [[(func(), b) for ((z + )) in [[0 for _ in range(1760)]] for b in [[ ( + "\n") if ii % 80 == 79 else " " for ii in range( + 1760)]] for o, D, N in [(o, D, N) for j in range(( + 0), 628, 7) for i in range(0, 628, 2) for (c, d, e,( +f), g, l, m, n) in [(sin( i / 100), cos(j / 100),( +sin(A)), sin(j / 100), cos(A), cos(i / 100) , +cos(B), sin(B))] for (h) in [d + 2] for ( +D, t) in [ (1 / ( c * h * e + f * g + (5 +)), c * h * g - f * e)] for (x, y) in [ +(int( 40 + 30 * D * ( l * h * m - t * n)), +int( 12 + 15 * D * ( l * h * n + t * (m))))] + for (o, N) in [(x + 80 * y,int(8 * (( f * e - c + * d * g) * m - c * d * e - f * g - l * d * n)))] if + 0 < x < 80 and 22 > y > 0] if D > z[o] for func in + [lambda: (z.pop((o))), lambda: z.insert((o), (D) + ),(lambda: (b.pop( o))), lambda: b.insert((o), + ".,-~:;=!*#$@"[ N if N > 0 else 0])]][ 0][1] + ] for pr in [lambda: print("\x1b[H"), + lambda: print("".join(b))] if (A := + A + 0.02) and ( B := B + 0.02)] + #..--~~EvanZhouDev:~~--.# + #...,2023,...# \ No newline at end of file diff --git a/DSA/Linked_List/self_referential.py b/DSA/Linked_List/self_referential.py deleted file mode 100644 index 0750143..0000000 --- a/DSA/Linked_List/self_referential.py +++ /dev/null @@ -1,53 +0,0 @@ -""" -Implementation of LinkedList Data structure in Python -""" - - -# Node class -class Node: - - # Function to initialize the node object - def __init__(self, data): - self.data = data # Assign data - self.next = None # Initialize next as null - - -# Linked List class - - -class LinkedList: - - # Function to initialize the Linked List object - def __init__(self): - self.head = None - - # function insert a new node at the beginning - def push(self, data): - # 1 & 2: allocate the Node and put in the data - new_node = Node(data=data) - - # 3. Make next of new Node as head - new_node.next = self.head - - # 4. Move the head to point to new Node - self.head = new_node - - -# Create a new linked list -my_linked_list = LinkedList() - -# Test the push method to insert nodes at the beginning -my_linked_list.push(1) -my_linked_list.push(2) -my_linked_list.push(3) - -# Print the linked list to verify the insertions -# It should print: 3 -> 2 -> 1 - -current_node = my_linked_list.head -while current_node: - print(current_node.data, end=" -> ") - current_node = current_node.next -print("None") - -# You can also add more test cases to test other methods you might implement From 5c47a896c13c64b9cb044db6a6f28cab4a4845f5 Mon Sep 17 00:00:00 2001 From: WazedKhan Date: Tue, 31 Oct 2023 22:08:23 +0600 Subject: [PATCH 4/7] node class --- DSA/Linked_List/define.ipynb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/DSA/Linked_List/define.ipynb b/DSA/Linked_List/define.ipynb index 5fd5183..26bc6ec 100644 --- a/DSA/Linked_List/define.ipynb +++ b/DSA/Linked_List/define.ipynb @@ -11,6 +11,21 @@ " self.head = None" ] }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "class Node:\n", + " def __init__(self, data):\n", + " self.data = data\n", + " self.next = None\n", + "\n", + " def __repr__(self):\n", + " self.data" + ] + }, { "cell_type": "code", "execution_count": null, From 3b883dee6a70791cf2f086be3884a69b389547c6 Mon Sep 17 00:00:00 2001 From: WazedKhan Date: Tue, 31 Oct 2023 22:11:45 +0600 Subject: [PATCH 5/7] __repr__ method for linkedList --- DSA/Linked_List/define.ipynb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/DSA/Linked_List/define.ipynb b/DSA/Linked_List/define.ipynb index 26bc6ec..4a9d69a 100644 --- a/DSA/Linked_List/define.ipynb +++ b/DSA/Linked_List/define.ipynb @@ -8,7 +8,16 @@ "source": [ "class LinkedList:\n", " def __init__(self):\n", - " self.head = None" + " self.head = None\n", + "\n", + " def __repr__(self) -> str:\n", + " node = self.head\n", + " nodes = []\n", + " while node is not None:\n", + " nodes.append(node.data)\n", + " node = node.next\n", + " nodes.append(None)\n", + " return \"->\".join(nodes)\n" ] }, { From 079a4625299924a3b663d4b1aad68b190d5fabe1 Mon Sep 17 00:00:00 2001 From: WazedKhan Date: Tue, 31 Oct 2023 22:14:48 +0600 Subject: [PATCH 6/7] create first linkedList --- DSA/Linked_List/define.ipynb | 47 ++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/DSA/Linked_List/define.ipynb b/DSA/Linked_List/define.ipynb index 4a9d69a..cd4122b 100644 --- a/DSA/Linked_List/define.ipynb +++ b/DSA/Linked_List/define.ipynb @@ -2,7 +2,22 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "class Node:\n", + " def __init__(self, data):\n", + " self.data = data\n", + " self.next = None\n", + "\n", + " def __repr__(self):\n", + " return self.data" + ] + }, + { + "cell_type": "code", + "execution_count": 15, "metadata": {}, "outputs": [], "source": [ @@ -10,29 +25,35 @@ " def __init__(self):\n", " self.head = None\n", "\n", - " def __repr__(self) -> str:\n", + " def __repr__(self):\n", " node = self.head\n", " nodes = []\n", " while node is not None:\n", " nodes.append(node.data)\n", " node = node.next\n", - " nodes.append(None)\n", - " return \"->\".join(nodes)\n" + " nodes.append(\"None\")\n", + " return \" -> \".join(nodes)" ] }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 14, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "None" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "class Node:\n", - " def __init__(self, data):\n", - " self.data = data\n", - " self.next = None\n", - "\n", - " def __repr__(self):\n", - " self.data" + "l_list = LinkedList()\n", + "l_list" ] }, { From 4d647233ead7c85aaab478a840c7d3f892247b30 Mon Sep 17 00:00:00 2001 From: WazedKhan Date: Wed, 1 Nov 2023 20:38:03 +0600 Subject: [PATCH 7/7] create next value --- DSA/Linked_List/define.ipynb | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/DSA/Linked_List/define.ipynb b/DSA/Linked_List/define.ipynb index cd4122b..19d614c 100644 --- a/DSA/Linked_List/define.ipynb +++ b/DSA/Linked_List/define.ipynb @@ -58,10 +58,33 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "first_node = Node(\"a\")\n", + "l_list.head = first_node" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [], + "source": [ + "second_node = Node(\"b\")\n", + "third_node = Node(\"c\")" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [], + "source": [ + "first_node.next = second_node\n", + "second_node.next =third_node" + ] } ], "metadata": {