Added a merge sort, to sort by degrees to the input.