0% found this document useful (0 votes)
1 views2 pages

Binary Search Program

Uploaded by

scarletchigoro8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views2 pages

Binary Search Program

Uploaded by

scarletchigoro8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

'binary search program

Module Module1
Sub Main()
Dim ARR() As Integer = {5, 6, 7, 10, 12, 15,
19, 20, 21, 22}
Dim lb As Integer = 0
Dim ub As Integer = UBound(ARR)
'ARR.Length - 1
Dim mid As Integer
Dim item As Integer = 18
Dim flag As Boolean = False

While lb <= ub
mid = (lb + ub) \ 2
If ARR(mid) = item Then
Console.WriteLine("item found " & mid)
' flag = True
Exit While
ElseIf ARR(mid) > item Then
ub = mid - 1
ElseIf ARR(mid) < item Then
lb = mid + 1
'Else
' Console.WriteLine("item not found")
End If
End While
If lb > ub Then
Console.WriteLine("item not found")

End If
'If flag = True Then
' Console.WriteLine("item found " & mid)
'Else
' Console.WriteLine("item not found ")
'End If
Console.ReadLine()
End Sub
End Module

You might also like