quicksort_indices_integer Subroutine

private recursive subroutine quicksort_indices_integer(values, indices, low, high, ascending)

Quicksort implementation for integer value indices

Recursive quicksort algorithm that sorts indices based on integer values

@param[in] values Integer 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

Arguments

Type IntentOptional Attributes Name
integer(kind=ik), intent(in), dimension(:) :: values
integer, intent(inout), dimension(:) :: indices
integer, intent(in) :: low
integer, intent(in) :: high
logical, intent(in) :: ascending

Source Code

    recursive subroutine quicksort_indices_integer(values, indices, low, high, ascending)
        integer(ik), 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_integer(values, indices, low, high, ascending)
            call quicksort_indices_integer(values, indices, low, pivot_idx - 1, ascending)
            call quicksort_indices_integer(values, indices, pivot_idx + 1, high, ascending)
        end if
    end subroutine quicksort_indices_integer