Quicksort implementation for real value indices
Recursive quicksort algorithm that sorts indices based on real values
@param[in] values Real values to sort by @param[in,out] indices Index array to be sorted @param[in] low Lower bound of sorting range @param[in] high Upper bound of sorting range @param[in] ascending Sort direction
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=rk), | intent(in), | dimension(:) | :: | values | ||
integer, | intent(inout), | dimension(:) | :: | indices | ||
integer, | intent(in) | :: | low | |||
integer, | intent(in) | :: | high | |||
logical, | intent(in) | :: | ascending |
recursive subroutine quicksort_indices_real(values, indices, low, high, ascending) real(rk), dimension(:), intent(in) :: values integer, dimension(:), intent(inout) :: indices integer, intent(in) :: low, high logical, intent(in) :: ascending integer :: pivot_idx if (low < high) then pivot_idx = partition_indices_real(values, indices, low, high, ascending) call quicksort_indices_real(values, indices, low, pivot_idx - 1, ascending) call quicksort_indices_real(values, indices, pivot_idx + 1, high, ascending) end if end subroutine quicksort_indices_real