Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Given pointers to the heads of two sorted linked lists, merge them into a single, sorted linked list. Either head pointer may be null meaning
Given pointers to the heads of two sorted linked lists, merge them into a single, sorted linked list. Either head pointer may be null meaning that the corresponding list is empty.
Example
headA refers to NULL
headB refers to NULL
The new list is
Function Description
Complete the mergeLists function in the editor below.
mergeLists has the following parameters:
SinglyLinkedListNode pointer headA: a reference to the head of a list
SinglyLinkedListNode pointer headB: a reference to the head of a list
Returns
SinglyLinkedListNode pointer: a reference to the head of the merged list
Input Format
The first line contains an integer t the number of test cases.
The format for each test case is as follows:
The first line contains an integer n the length of the first linked list.
The next n lines contain an integer each, the elements of the linked list.
The next line contains an integer m the length of the second linked list.
The next m lines contain an integer each, the elements of the second linked list.
Constraints
t
n m
listi where listi is the ith element of the list.
Sample Input
Sample Output
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started