sort_integer Subroutine

public recursive subroutine sort_integer(g, d, itabref)


Arguments

Type IntentOptional AttributesName
integer(kind=I4), intent(in) :: g
integer(kind=I4), intent(in) :: d
integer(kind=I4), intent(inout), dimension(:):: itabref

Contents

Source Code


Source Code

   recursive subroutine sort_integer(g, d, itabref)
      implicit none
      integer(kind=I4), intent(in)  :: g, d
      integer(kind=I4), dimension(:), intent(inout)  :: itabref
      integer(kind=I4) :: i, j, mil
      integer(kind=I4)  :: tmp, cle
      i = g
      j = d
      mil = (g+d)/2
      cle = itabref(mil)

      if (g>=d) return

      do while (i<=j)
         do while (itabref(i)<cle)
            i = i + 1
         enddo
         do while (itabref(j)>cle)
            j = j - 1
         enddo
         if (i<=j) then
            ! échange des éléments du tableau
            tmp = itabref(i)
            itabref(i) = itabref(j)
            itabref(j) = tmp
            ! échange des éléments du vecteur position
            i = i + 1
            j = j - 1
         endif
      enddo

      if (g<j) call sort_integer(g, j, itabref)
      if (d>i) call sort_integer(i, d, itabref)

   return
   endsubroutine sort_integer