InsertionSort
Insertion sort (in-place) algorithm.
Reference: coretran
Calling example:
CALL InsertionSort(array, low, high)
Interface
- ܀ Interface
- ️܀ See example
- ↢
MODULE PURE SUBROUTINE InsertionSort(array, low, high)
INTEGER(Int8| Int16 | Int32 | Int64) | REAL(Real32| Real64), INTENT(INOUT) :: array(:)
INTEGER(I4B), INTENT(IN) :: low
INTEGER(I4B), INTENT(IN) :: high
END SUBROUTINE InsertionSort
In this example we test InsertionSort
method.
program main
use easifembase
implicit none
integer(i4b), allocatable :: intvec( : )
real(dfp), allocatable :: realvec( : )
intvec = [ 5, 4, 3, 2, 1 ]
call InsertionSort(array=intvec, low=1, high=SIZE(intvec) )
call display( intvec, "intvec = " )
See results
intvec =
---------
1
2
3
4
5
realvec = [ 5, 4, 3, 2, 1 ]
call InsertionSort( realvec, 1, SIZE( realvec ) )
call display( realvec, "realvec = " )
See results
realvec =
----------
1.00000
2.00000
3.00000
4.00000
5.00000
end program main