I keep getting into an infinite loop when using my function merge_sorted for my linked lists. Please help. Thanks :)
I went through my merge_sort function and it seems okay. It updates the curr1 and curr2 inside the loop but I am not sure why I get into the infinite loop.
def merge_sorted(root1,root2):"""Ascending Order""" if root1 == None: return root2 if root2 == None: return root1 curr1 = root1 curr2 = root2 new_root = None new_tail = None # init r and t if curr1.val > curr2.val: new_root = curr2 new_tail = curr2 else: # curr1.val <= curr2.val new_root = curr1 new_tail = curr1 # merge while curr1 and curr2: if curr1.val > curr2.val: # curr2 goes first new_tail.nxt = curr2 new_tail = new_tail.nxt curr2 = curr2.nxt else: # curr1.val <= curr2.val # curr1 goes first new_tail.nxt = curr1 new_tail = new_tail.nxt curr1 = curr1.nxt if curr1: new_tail.nxt = curr1 if curr2: new_tail.nxt = curr2 return new_root