Imports System
Public Class Test
Public Shared Function recursive_binary_search(arr() As Integer, left As Integer, right As Integer, to_find As Integer) As Integer
if (right >= left) then
Dim mid As Integer = left + Convert.ToInt32((right - left) / 2)
If (arr(mid) = to_find) then
return mid
End If
If (arr(mid) > to_find) then
return recursive_binary_search(arr, left, mid - 1, to_find)
Else
return recursive_binary_search(arr, mid + 1, right, to_find)
End If
End If
return -1
End Function
Public Shared Sub Main()
Dim arr() As Integer = { 2, 3, 6, 7, 12, 13, 17, 19, 21 }
Dim to_find As Integer = 13
Dim result As Integer = recursive_binary_search(arr, 0, arr.Length - 1, to_find)
If (result = -1) Then
Console.WriteLine("Not found")
else
Console.WriteLine("Found at index: {0}", result)
End If
End Sub
End Class
' run:
'
' Found at index: 5
'