Problem
The problem of sorting a list of numbers lends itself immediately to a divide-and-conquer strategy: split the list into two halves, recursively sort each half, and then merge the two sorted sublists (recall the problem “Merge Two Sorted Arrays”).
Source: Algorithms by Dasgupta, Papadimitriou, Vazirani. McGraw-Hill. 2006.
Given: A positive integer and an array of integers from to .
Return: A sorted array .
对数字列表进行排序的问题立即使其适用于分而治之的 策略:将列表分为两半,递归地对每一半进行排序,然后合并两个已排序的子列表(回想一下“合并两个已排序数组”的问题) 。
资料来源:Dasgupta,Papadimitriou,Vazirani的算法。麦格劳-希尔。2006年。
给定:正整数 和一个数组 来自的整数 至 。
返回:排序数组。
Sample Dataset
10 20 19 35 -18 17 -20 20 1 4 4
Sample Output
-20 -18 1 4 4 17 19 20 20 35