@@ -24,18 +24,23 @@ integers, with the value 0 indicating off-the-end (e.g. "not found").
24
24
Sorting
25
25
=======
26
26
27
+ All sorting functions
28
+
29
+ Sort
30
+ ----
31
+
27
32
Sorting and checking order is a single simple subroutine call::
28
33
29
34
use flc_algorithm, only : sort, is_sorted
30
35
implicit none
31
36
integer, dimension(5) :: iarr = [ 2, 5, -2, 3, -10000]
32
- logical :: result
37
+ logical :: sortitude
33
38
34
39
call sort(iarr)
35
- result = is_sorted(iarr)
40
+ sortitude = is_sorted(iarr)
36
41
37
42
A routine that provides the indices that correspond to a sorted array, like
38
- Numpy's [argsort](https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.argsort.html) ,
43
+ Numpy's argsort _ ,
39
44
takes an array to analyze and an empty array of integers to fill::
40
45
41
46
use flc_algorithm, only : argsort
@@ -45,7 +50,7 @@ takes an array to analyze and an empty array of integers to fill::
45
50
46
51
call argsort(iarr, idx)
47
52
! This line prints a sorted array:
48
- write(*,*), iarr(idx)
53
+ write(*,*) iarr(idx)
49
54
50
55
Note that the index array is always a ``C_INT ``. On some compilers and
51
56
platforms, this may be the same as native Fortran integer, but it's not
@@ -55,6 +60,7 @@ The ``data`` and ``idx`` arguments to ``argsort`` *must* be the same size. If
55
60
the index array is larger than the data, invalid entries will be filled with
56
61
zero.
57
62
63
+ .. _argsort : https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.argsort.html
58
64
Searching
59
65
=========
60
66
@@ -68,15 +74,15 @@ Example::
68
74
69
75
use flc_algorithm, only : binary_search
70
76
implicit none
71
- integer :: index
77
+ integer :: idx
72
78
integer, dimension(6) :: iarr = [ -5, 1, 1, 2, 4, 9]
73
79
74
- index = binary_search(iarr, -100) ! returns 0
75
- index = binary_search(iarr, 1) ! returns 2
76
- index = binary_search(iarr, 2) ! returns 4
77
- index = binary_search(iarr, 3) ! returns 0
78
- index = binary_search(iarr, 9) ! returns 6
79
- index = binary_search(iarr, 10) ! returns 0
80
+ idx = binary_search(iarr, -100) ! returns 0
81
+ idx = binary_search(iarr, 1) ! returns 2
82
+ idx = binary_search(iarr, 2) ! returns 4
83
+ idx = binary_search(iarr, 3) ! returns 0
84
+ idx = binary_search(iarr, 9) ! returns 6
85
+ idx = binary_search(iarr, 10) ! returns 0
80
86
81
87
82
88
Set operations
0 commit comments