File: example_select.f90

package info (click to toggle)
fortran-stdlib 0.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 34,008 kB
  • sloc: f90: 24,178; ansic: 1,244; cpp: 623; python: 119; makefile: 13
file content (27 lines) | stat: -rw-r--r-- 672 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
program example_select
  use stdlib_selection, only: select
  implicit none

  real, allocatable :: array(:)
  real :: kth_smallest
  integer :: k

  array = [3., 2., 7., 4., 5., 1., 4., -1.]

  k = 2
  call select(array, k, kth_smallest)
  print *, kth_smallest ! print 1.0

  k = 7
! Due to the previous call to select, we know for sure this is in an
! index >= 2
  call select(array, k, kth_smallest, left=2)
  print *, kth_smallest ! print 5.0

  k = 6
! Due to the previous two calls to select, we know for sure this is in
! an index >= 2 and <= 7
  call select(array, k, kth_smallest, left=2, right=7)
  print *, kth_smallest ! print 4.0

end program example_select