You are given two sorted lists having head as
head1
and
head2
, write a program to
merge
them into one big sorted list
Problem Note:
- The two linked lists can be of different sizes
- The new list must be created by splicing together the nodes of the first two lists.
Example 1
Input: 10->12->13->42, 4->11->15
Output: 4->10->11->12->13->15->42
Explanation: The two lists are merged to form a sorted list having all elements of both the lists.
Example 2
Input: 2->5->9, 12->14->17
Output: 2->5->9->12->14->17
Explanation: The two lists are merged to form a sorted list having all elements of both the lists.
Example 3
Input: 8, 4->12
Output: 4->8->12
Explanation: The two lists are merged to form a sorted list having all elements of both the lists.