partition_real Function

private function partition_real(arr, low, high) result(pivot_index)

Arguments

Type IntentOptional Attributes Name
real(kind=rk), intent(inout) :: arr(:)
integer, intent(in) :: low
integer, intent(in) :: high

Return Value integer


Source Code

    function partition_real(arr, low, high) result(pivot_index)
        real(rk), intent(inout) :: arr(:)
        integer, intent(in) :: low, high
        integer :: pivot_index
        real(rk) :: pivot, temp
        integer :: i, j

        pivot = arr(high)
        i = low - 1

        do j = low, high - 1
            if (arr(j) <= pivot) then
                i = i + 1
                temp = arr(i)
                arr(i) = arr(j)
                arr(j) = temp
            end if
        end do

        temp = arr(i + 1)
        arr(i + 1) = arr(high)
        arr(high) = temp
        pivot_index = i + 1
    end function partition_real