1 module module_mergesort
5 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
9 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10 recursive subroutine mergesort(array, n1, n2)
15 integer, intent(in) :: n1, n2
16 integer, dimension(n1:n2), intent(inout) :: array
21 real, dimension(1:n2-n1+1) :: temp
25 if (n2 - n1 == 1) then
26 if (array(n1) < array(n2)) then
34 call mergesort(array(n1:n1+(n2-n1+1)/2), n1, n1+(n2-n1+1)/2)
35 call mergesort(array(n1+((n2-n1+1)/2)+1:n2), n1+((n2-n1+1)/2)+1, n2)
38 j = n1 + ((n2-n1+1)/2) + 1
40 do while (i <= n1+(n2-n1+1)/2 .and. j <= n2)
41 if (array(i) > array(j)) then
52 if (i <= n1+(n2-n1+1)/2) then
53 do while (i <= n1+(n2-n1+1)/2)
66 array(n1:n2) = temp(1:k-1)
68 end subroutine mergesort
70 end module module_mergesort