Examples in Gambas (#5) by @vdelacruzjardon
This commit is contained in:
committed by
Aditya Bhargava
parent
e2a4153e80
commit
0aec97dbf2
Binary file not shown.
@@ -0,0 +1,7 @@
|
||||
# Gambas Project File 3.0
|
||||
# Compiled with Gambas 3.5.4
|
||||
Title=01_binary_search
|
||||
Startup=binary_search
|
||||
Version=0.0.1
|
||||
TabSize=2
|
||||
Packager=1
|
||||
@@ -0,0 +1,27 @@
|
||||
' Gambas module file
|
||||
|
||||
Function binary_search(list As Float[], item As Float) As Variant
|
||||
Dim low, high, Midd, guess As Float
|
||||
low = 0
|
||||
high = list.Length - 1
|
||||
While low <= high
|
||||
Midd = (low + high)
|
||||
guess = list[Midd]
|
||||
If guess = item Then
|
||||
Return Midd
|
||||
Else If guess > item Then
|
||||
high = Midd - 1
|
||||
Else
|
||||
low = Midd + 1
|
||||
Endif
|
||||
Wend
|
||||
Return Null
|
||||
End
|
||||
|
||||
Public Sub Main()
|
||||
|
||||
Dim my_list As New Float[]
|
||||
my_list = [1, 3, 5, 7, 9]
|
||||
Print binary_search(my_list, 3) '1
|
||||
Print binary_search(my_list, -1) 'null
|
||||
End
|
||||
@@ -0,0 +1,7 @@
|
||||
binary_search
|
||||
01_binary_search
|
||||
0
|
||||
0
|
||||
0.0.1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user