Skip to content

Commit

Permalink
Advanced Task
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronnie5562 committed Jul 24, 2023
1 parent ff89bab commit 38f8718
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions python-classes/100-singly_linked_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def next_node(self, value):
if (not isinstance(value, Node) and value is not None):
raise TypeError("next_node must be a Node object")
self.__next_node = value



class SinglyLinkedList:
"""This class represents a singly-linked list."""

Expand All @@ -54,15 +55,15 @@ def sorted_insert(self, value):
value (Node): The new Node to insert.
"""
new_node = Node(value)
if self.__head == None:
if self.__head is None:
self.__head = new_node
elif self.__head.data > new_node.data:
new_node.next_node = self.__head
self.__head = new_node
else:
current_node = self.__head
while (current_node.next_node is not None and
current_node.next_node.data < value):
current_node.next_node.data < value):
current_node = current_node.next_node
new_node.next_node = current_node.next_node
current_node.next_node = new_node
Expand Down

0 comments on commit 38f8718

Please sign in to comment.