HeapSort
This subroutine implements heap sort algorithm to sort the array inplace.
Calling example:
CALL HeapSort(array)
Interface
- ܀ Interface
- ️܀ See example
- ↢
MODULE PURE SUBROUTINE HeapSort(array)
INTEGER(Int8| Int16 | Int32 | Int64) | REAL(Real32| Real64), INTENT(INOUT) :: array(:)
END SUBROUTINE HeapSort
PROGRAM main
USE easifemBase
real(real32) :: avec(10)
call RANDOM_NUMBER(avec)
avec = avec * 10
call Display( avec, msg="r32 Before sorting = ", advance="NO" )
call HeapSort(avec )
call Display( avec, msg="r32 After sorting = " )
call blanklines()
See results
r32 Before sorting | r32 After sorting |
---|---|
8.13609 | 0.72018 |
9.81305 | 1.10549 |
5.17501 | 2.40877 |
0.72018 | 3.13865 |
6.35550 | 4.40301 |
3.13865 | 5.17501 |
9.25757 | 6.35550 |
1.10549 | 8.13609 |
2.40877 | 9.25757 |
4.40301 | 9.81305 |
END PROGRAM main