#C12373. Merge Sort Algorithm
Merge Sort Algorithm
Merge Sort Algorithm
This problem requires you to implement the merge sort algorithm. Merge sort is a classic divide and conquer sorting algorithm with a time complexity of \(O(n\log n)\). You are required to sort a given list of integers in ascending order. The merge sort algorithm works by dividing the list into two halves, recursively sorting the halves, and then merging the sorted halves together.
Detailed Explanation:
- Divide: The list is divided into two halves.
- Conquer: Recursively sort each half.
- Combine: Merge the two sorted halves into one sorted sequence. The merging process involves comparing the smallest unmerged elements in each half and adding the smaller element into the new list.
Remember that you must implement the merge sort using the merge function to combine two sorted lists.
inputFormat
The input is read from stdin and consists of two lines:
- The first line contains a single integer \(n\) representing the number of elements.
- The second line contains \(n\) space-separated integers.
outputFormat
Output the sorted list of integers in ascending order to stdout as a single line, with each number separated by a space.
## sample6
34 7 23 32 5 62
5 7 23 32 34 62