'Visual Basic 2010 Recursie Procedures en Functies Module Exercise4Solution Sub Main() Dim numbers As Integer() = {1, 3, 4, 7, 9, 10, 11, 15, 18, 20} ' Dim number, lowerbound, upperbound As Integer Dim found As Boolean ' number = 15 lowerbound = 0 upperbound = 9 found = BinarySearch(number, numbers, lowerbound, upperbound) Console.WriteLine(found) ' True ' number = 18 lowerbound = 0 upperbound = 7 found = BinarySearch(number, numbers, lowerbound, upperbound) Console.WriteLine(found) ' False ' Console.ReadLine() End Sub Function BinarySearch(ByVal number As Integer, _ ByVal array As Integer(), _ ByVal lowerbound As Integer, _ ByVal upperbound As Integer) As Boolean Dim middle As Integer = (lowerbound + upperbound) \ 2 If (number = array(middle)) Then BinarySearch = True Else If (upperbound <= lowerbound) Then BinarySearch = False Else If number > array(middle) Then lowerbound = middle + 1 Else upperbound = middle - 1 End If BinarySearch = BinarySearch(number, array, lowerbound, upperbound) End If End If End Function End Module 'Bezoek www.vbvoorbeelden.be voor meer Visual Basic voorbeelden. 'Copyright - De Wolf / vbvoorbeelden - 2003-2011 - Alle rechten voorbehouden.