quicksort_integer Subroutine

public recursive subroutine quicksort_integer(arr, left, right)

Arguments

Type IntentOptional Attributes Name
integer, intent(inout) :: arr(:)
integer, intent(in) :: left
integer, intent(in) :: right

Called by

proc~~quicksort_integer~~CalledByGraph proc~quicksort_integer quicksort_integer proc~quicksort_integer->proc~quicksort_integer proc~select_slice select_slice proc~select_slice->proc~quicksort_integer proc~put_slice put_slice proc~put_slice->proc~select_slice proc~write_slice write_slice proc~write_slice->proc~put_slice proc~saveamrfile saveamrfile proc~saveamrfile->proc~write_slice proc~timeintegration timeintegration proc~timeintegration->proc~saveamrfile proc~main main proc~main->proc~timeintegration program~agile agile program~agile->proc~main

Source Code

  recursive subroutine quicksort_integer(arr, left, right)
    integer, intent(inout) :: arr(:)
    integer, intent(in) :: left, right
    integer :: i, j, pivot, temp

    if (left < right) then
       pivot = arr((left + right) / 2)
       i = left
       j = right

       do
          do while (arr(i) < pivot)
             i = i + 1
          end do
          do while (arr(j) > pivot)
             j = j - 1
          end do

          if (i >= j) exit

          temp = arr(i)
          arr(i) = arr(j)
          arr(j) = temp
          i = i + 1
          j = j - 1
       end do

       call quicksort_integer(arr, left, j)
       call quicksort_integer(arr, j + 1, right)
    end if

  end subroutine quicksort_integer