Use an in-place quick select on an array of numbers
Example usage
program selectTest use variableKind use m_strings, only: str use m_allocate, only: allocate use m_random, only: rngInteger,rngNormal use m_select, only: select real(r64),allocatable :: d1D(:) integer(i32),allocatable :: i1D(:) integer(i32) :: k real(r64) :: dv integer(i32) :: iv write(*,'(a)') 'Select the kth smallest element from a 10000 length array of random double precision numbers' call allocate(d1D, 10000) call rngNormal(d1D) k = (1+size(d1D))/2 dv = select(d1D,k) write(*,'(a)') 'kth element? '//str(dv) write(*,'(a)') 'Select the kth smallest element from a 10000 length array of random integers'' call allocate(i1D, 10000) call rngInteger(i1D) iv = select(i1D, k) write(*,'(a)') 'kth element? '//str(iv) end program
Interfaced with select()
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=i32), | intent(inout) | :: | this(:) | Array to choose kth smallest from |
||
integer(kind=i32), | intent(in) | :: | k | kth smallest element |
||
integer(kind=i32) | :: | res |
Interfaced with select()
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=i64), | intent(inout) | :: | this(:) | Array to choose kth smallest from |
||
integer(kind=i32), | intent(in) | :: | k | kth smallest element |
||
integer(kind=i64) | :: | res |
Interfaced with select()
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=r32), | intent(inout) | :: | this(:) | Array to choose kth smallest from |
||
integer(kind=i32), | intent(in) | :: | k | kth smallest element |
||
real(kind=r32) | :: | res |
Interfaced with select()
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=r64), | intent(inout) | :: | this(:) | Array to choose kth smallest from |
||
integer(kind=i32), | intent(in) | :: | k | kth smallest element |
||
real(kind=r64) | :: | res |