Examples in Gambas (#5) by @vdelacruzjardon

This commit is contained in:
vdelacruzjardon
2016-09-16 13:41:52 -05:00
committed by Aditya Bhargava
parent e2a4153e80
commit 0aec97dbf2
41 changed files with 355 additions and 0 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -0,0 +1,7 @@
binary_search
01_binary_search
0
0
0.0.1