#C13992. Merge Sorted Linked Lists
Merge Sorted Linked Lists
Merge Sorted Linked Lists
You are given two sorted singly linked lists. Your task is to merge them into a single sorted linked list.
Implement a function \(merge\_linked\_lists(l1, l2)\) that merges two sorted linked lists. Each node in the linked list contains an integer value. The function should maintain the sorted order, running in \(O(n)\) time complexity.
If one of the lists is empty, the function should return the non-empty list. If both lists are empty, return an empty list.
Example: If the input lists are \([1, 3, 5]\) and \([2, 4, 6]\), then the merged linked list should be \([1, 2, 3, 4, 5, 6]\).
inputFormat
The input consists of two lines read from standard input (stdin):
- The first line contains a series of space-separated integers representing the first sorted linked list. If the line is empty, the list is considered empty.
- The second line contains a series of space-separated integers representing the second sorted linked list. Similarly, if the line is empty, the list is considered empty.
outputFormat
Output the merged sorted linked list as a single line of space-separated integers to standard output (stdout). If the resulting list is empty, output an empty line.
## sample1 3 5
2 4 6
1 2 3 4 5 6