Question

Question 3:

In this question, we will implement a function that merges two sorted linked lists:

def merge_linked_lists (srt_lnk_lst1, srt_lnk_1st2)

This function is given two doubly linked lists of integers srt_lnk_lst1 and

srt_lnk_1st2. The elements in srt_lnk_lst1 and srt_lnk_1st2 are sorted.

That is, they are ordered in the lists, in an ascending order.

When the function is called, it will create and return a new doubly linked list, that

contains all the elements that appear in the input lists in a sorted order.

For example:

if srt_lnk_1st1= [1 <--> 3 <--> 5 <--> 6 <--> 8],

and srt 1nk 1st2=[2 <--> 3 <--> 5 <--> 10 <--> 15 <--> 18],

calling: merge_linked_lists (srt_lnk_lst1, srt_lnk_lst2), should

create and return a doubly linked list that contains:

[1 <--> 2 <--> 3 <--> 3 <--> 5 <--> 5 <--> 6 <--> 8 <--> 10 <--> 15 <--> 18].

The merge_linked_lists function is not recursive, but it defines and calls

merge_sublists - a nested helper recursive function.

Question image 1