From fdbea27d4137ccb8b4a8f5f8d346ca92590f2086 Mon Sep 17 00:00:00 2001 From: mjk22071998 Date: Tue, 1 Oct 2024 15:22:35 +0500 Subject: [PATCH] updated merge function --- data_structures/linked_list/sorted_linked_list.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/data_structures/linked_list/sorted_linked_list.py b/data_structures/linked_list/sorted_linked_list.py index 8d1f43d09..8a133e568 100644 --- a/data_structures/linked_list/sorted_linked_list.py +++ b/data_structures/linked_list/sorted_linked_list.py @@ -331,12 +331,15 @@ class SortedLinkedList: """ if other_list.head is None: return - if self.head is None: + elif self.head is None: self.head = other_list.head self.tail = other_list.tail return - self.tail.next_node = other_list.head - self.tail = other_list.tail + else: + temp=otherother_list.head + while temp: + self.insert(temp.data) + temp=temp.next_node if __name__ == "__main__":