updated merge function

This commit is contained in:
mjk22071998 2024-10-01 15:22:35 +05:00
parent d96cc64ce7
commit fdbea27d41

View File

@ -331,12 +331,15 @@ class SortedLinkedList:
""" """
if other_list.head is None: if other_list.head is None:
return return
if self.head is None: elif self.head is None:
self.head = other_list.head self.head = other_list.head
self.tail = other_list.tail self.tail = other_list.tail
return return
self.tail.next_node = other_list.head else:
self.tail = other_list.tail temp=otherother_list.head
while temp:
self.insert(temp.data)
temp=temp.next_node
if __name__ == "__main__": if __name__ == "__main__":