Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in), | dimension(:) | :: | x | Input array |
pure recursive function sort(x) result(res)
real(wp), dimension(:), intent(in) :: x !< Input array
real(wp), dimension(size(x)) :: res
real(wp), dimension(size(x)-1) :: rest
real(wp) :: pivot
if(size(x) > 1)then
pivot = head(split(x, 2))
rest = [split(x, 1), tail(split(x, 2))]
res = [sort(pack(rest, rest < pivot)), pivot, &
sort(pack(rest, rest >= pivot))]
else
res = x
endif
end function sort