new files
This commit is contained in:
parent
3af7344581
commit
86c034bb8b
1364 changed files with 21352 additions and 0 deletions
18
Task/Binary-search/Fortran/binary-search-1.f
Normal file
18
Task/Binary-search/Fortran/binary-search-1.f
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
recursive function binarySearch_R (a, value) result (bsresult)
|
||||
real, intent(in) :: a(:), value
|
||||
integer :: bsresult, mid
|
||||
|
||||
mid = size(a)/2 + 1
|
||||
if (size(a) == 0) then
|
||||
bsresult = 0 ! not found
|
||||
else if (a(mid) > value) then
|
||||
bsresult= binarySearch_R(a(:mid-1), value)
|
||||
else if (a(mid) < value) then
|
||||
bsresult = binarySearch_R(a(mid+1:), value)
|
||||
if (bsresult /= 0) then
|
||||
bsresult = mid + bsresult
|
||||
end if
|
||||
else
|
||||
bsresult = mid ! SUCCESS!!
|
||||
end if
|
||||
end function binarySearch_R
|
||||
Loading…
Add table
Add a link
Reference in a new issue