#C14314. Merge Sort Algorithm
Merge Sort Algorithm
Merge Sort Algorithm
You are given a list of integers. Your task is to sort the list in non-decreasing order using the Merge Sort algorithm. The Merge Sort algorithm is a divide and conquer algorithm with a worst-case time complexity of \(O(n \log n)\). The algorithm recursively divides the list into two halves, sorts each half, and then merges the sorted halves to produce the sorted list.
The program must read input from standard input (stdin) and output the sorted list to standard output (stdout). The input is provided as a single line of space-separated integers. If the input line is empty, it should be considered as an empty list.
Note: If any element cannot be parsed as an integer, an error message will be printed.
inputFormat
The input consists of a single line containing space separated integers. For example: 3 1 4 5 2
. If the line is empty, it represents an empty list.
Input Format:
<integer> [<integer> ...]
outputFormat
Output the sorted list in non-decreasing order as space separated integers on a single line.
Output Format:
<integer> [<integer> ...]## sample
1 2 3 4 5
1 2 3 4 5