From fa29e39c2a1142668bcbbd03a8583bc29c0a5395 Mon Sep 17 00:00:00 2001 From: mjk22071998 Date: Tue, 1 Oct 2024 15:56:54 +0500 Subject: [PATCH] "Updated type hints for Optional[Node] to Node | None in SortedLinkedList class" --- data_structures/linked_list/sorted_linked_list.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/data_structures/linked_list/sorted_linked_list.py b/data_structures/linked_list/sorted_linked_list.py index 645c7751b..c3386a460 100644 --- a/data_structures/linked_list/sorted_linked_list.py +++ b/data_structures/linked_list/sorted_linked_list.py @@ -65,7 +65,7 @@ class SortedLinkedList: 'SortedLinkedList(2, 12, 21, 23, 72)' """ nodes = [] - temp: Optional[Node] = self.head + temp: Node | None = self.head while temp: nodes.append(str(temp.data)) temp = temp.next_node @@ -95,7 +95,7 @@ class SortedLinkedList: new_node.next_node = self.head self.head = new_node else: - temp_node: Optional[Node] = self.head + temp_node: Node | None = self.head while temp_node.next_node and temp_node.next_node.data < data: temp_node = temp_node.next_node new_node.next_node = temp_node.next_node @@ -117,7 +117,7 @@ class SortedLinkedList: >>> linkedList.display() 32 45 57 """ - temp: Optional[Node] = self.head + temp: Node | None = self.head while temp: print(temp.data, end=" ") temp = temp.next_node @@ -158,7 +158,7 @@ class SortedLinkedList: self.tail = None return True - temp_node: Optional[Node] = self.head + temp_node: Node | None = self.head while temp_node.next_node: if temp_node.next_node.data == data: temp_node.next_node = temp_node.next_node.next_node @@ -189,7 +189,7 @@ class SortedLinkedList: >>> linkedList.search(90) False """ - temp: Optional[Node] = self.head + temp: Node | None = self.head while temp: if temp.data == data: return True @@ -301,7 +301,7 @@ class SortedLinkedList: 32 45 57 """ - temp: Optional[Node] = self.head + temp: Node | None = self.head while temp and temp.next_node: if temp.data == temp.next_node.data: temp.next_node = temp.next_node.next_node @@ -335,7 +335,7 @@ class SortedLinkedList: self.tail = other_list.tail return else: - temp: Optional[Node] = other_list.head + temp: Node | None = other_list.head while temp: self.insert(temp.data)