#C12221. Merge Two Sorted Lists
Merge Two Sorted Lists
Merge Two Sorted Lists
Given two sorted lists of integers, your task is to merge them into a single sorted list without using any built-in sorting functions. You are required to implement an efficient algorithm using the two-pointer technique.
If one or both lists are empty, treat them accordingly. The input will be provided via standard input as two lines where each line represents a sorted list in ascending order with elements separated by spaces. An empty line represents an empty list.
The final output should be the merged sorted list printed on a single line with elements separated by a single space.
inputFormat
The input consists of two lines:
- The first line contains a sorted list of integers separated by spaces. It may be empty.
- The second line contains another sorted list of integers separated by spaces. It may also be empty.
Both lists are guaranteed to be in ascending order.
outputFormat
Print the merged sorted list on a single line. The list should contain all the numbers from both input lists in ascending order, separated by a single space.
## sample1 3 5 7
2 4 6 8
1 2 3 4 5 6 7 8