insertion_sort Subroutine

public pure subroutine insertion_sort(list)

Arguments

Type IntentOptional Attributes Name
integer, intent(inout) :: list(:)

Source Code

   pure subroutine insertion_sort(list)
      implicit none
      integer, intent(inout) :: list(:)

      integer :: i, j, key

      do i = 2, size(list, dim=1)
         key = list(i)
         j = i - 1

         do while(j > 0 .and. list(j) > key)
            list(j+1) = list(j)
            j = j - 1
            if (j == 0) exit
         end do
         list(j + 1) = key
      end do
   end subroutine insertion_sort