>>69333442

I wrote this simple insertion sort in F95

! Insertion sort for integer array "a" of size "n".

subroutine ArrayInsertionSort(a, n)

implicit none

integer, dimension (:), intent(inout) :: a

integer, intent(in) :: n

integer :: i, j

integer :: current_pos

integer :: new_pos

do i = 2, n

current_pos = a(i)

! Searching for new location for a(i):

new_pos = i

do while ( (new_pos > 1) .and. (a(new_pos-1) > current_pos) )

! Moving the previous cell backwards

a(new_pos) = a(new_pos - 1)

new_pos = new_pos - 1

end do

a(new_pos) = current_pos

end do

end subroutine