Applied Non safety

This commit is contained in:
mjk22071998 2024-10-01 16:07:48 +05:00
parent 3c76fcef53
commit 44ebb6632b

View File

@ -93,6 +93,7 @@ class SortedLinkedList:
self.head = new_node self.head = new_node
else: else:
temp_node: Node | None = self.head temp_node: Node | None = self.head
if temp:
while temp_node.next_node and temp_node.next_node.data < data: while temp_node.next_node and temp_node.next_node.data < data:
temp_node = temp_node.next_node temp_node = temp_node.next_node
new_node.next_node = temp_node.next_node new_node.next_node = temp_node.next_node
@ -156,6 +157,7 @@ class SortedLinkedList:
return True return True
temp_node: Node | None = self.head temp_node: Node | None = self.head
if temp_node:
while temp_node.next_node: while temp_node.next_node:
if temp_node.next_node.data == data: if temp_node.next_node.data == data:
temp_node.next_node = temp_node.next_node.next_node temp_node.next_node = temp_node.next_node.next_node