Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
18
Task/Binary-search/Visual-Basic-.NET/binary-search-1.vb
Normal file
18
Task/Binary-search/Visual-Basic-.NET/binary-search-1.vb
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
Function BinarySearch(ByVal A() As Integer, ByVal value As Integer) As Integer
|
||||
Dim low As Integer = 0
|
||||
Dim high As Integer = A.Length - 1
|
||||
Dim middle As Integer = 0
|
||||
|
||||
While low <= high
|
||||
middle = (low + high) / 2
|
||||
If A(middle) > value Then
|
||||
high = middle - 1
|
||||
ElseIf A(middle) < value Then
|
||||
low = middle + 1
|
||||
Else
|
||||
Return middle
|
||||
End If
|
||||
End While
|
||||
|
||||
Return Nothing
|
||||
End Function
|
||||
17
Task/Binary-search/Visual-Basic-.NET/binary-search-2.vb
Normal file
17
Task/Binary-search/Visual-Basic-.NET/binary-search-2.vb
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
Function BinarySearch(ByVal A() As Integer, ByVal value As Integer, ByVal low As Integer, ByVal high As Integer) As Integer
|
||||
Dim middle As Integer = 0
|
||||
|
||||
If high < low Then
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
middle = (low + high) / 2
|
||||
|
||||
If A(middle) > value Then
|
||||
Return BinarySearch(A, value, low, middle - 1)
|
||||
ElseIf A(middle) < value Then
|
||||
Return BinarySearch(A, value, middle + 1, high)
|
||||
Else
|
||||
Return middle
|
||||
End If
|
||||
End Function
|
||||
Loading…
Add table
Add a link
Reference in a new issue