It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Visual Basic Forum

Binary Search Algorithm

Moderator: dafunkymunky

Binary Search Algorithm

Postby Dancari on Fri Nov 18, 2011 2:04 am

Hello,
All I am also taking a Visual Basic class and I am in need of a new pair of eyes are mine are bleeding at the moment with all the finals coming. I have my entire program written which is susposed to search my arrays using the binary search but this is mt second project and I have been at it since yesterday and I can no longer focus. If you can offer any coding help ot flaws i have made please do.
Thanks Again,
Dancari

Option strict on
written in English

Module Module1


Sub Main()
Dim strNames() As String = {"Boba", "Darth", "Han", "Luke", "Princess"}
Dim strPhone() As String = {"111-111-1111", "222-222-2222", "333-333- 3333", "444-444-4444", "555-555-5555"}
Dim strSearchName As String = ""
Dim intIndex As Integer = 0
Dim strAgain As String = "Y"
Dim intBinarySearch As Integer = 0

While strAgain = "Y"
Console.Write("Enter a name to search for. ")
strSearchName = CStr(Console.Read())

intBinarySearch = (strNames.GetUpperBound(0), strSearchName)
If intIndex <> -1 Then
Console.Write("The phone number is " & strPhone(intIndex))
Else
Console.Write(strSearchName & " was not found. ")

End If
Console.WriteLine("Do you want to search again? Y=Yes, N=No ")
strAgain = CStr(Console.Read())

End While



intBinarySearch = (strNames.getupperbound(0), strPhone())

Dim intFirst As Integer = 0
Dim intLast As Integer = strNames.getUpperBound(0) - 1
Dim intPosition As Integer = -1
Dim strBooleanFound = False
Dim intMiddle As Integer = 0


While <> strBooleanFound and intFirst <= intLast
intMiddle = intFirst + intLast / 2
If strNames.GetUpperBound(0) = intMiddle Then
strBooleanFound = True
intPosition = intMiddle

Else
If strNames.GetUpperBound(0) > intMiddle Then
intLast = intMiddle - 1

Else
intFirst = intMiddle + 1

End If


End If

End While

End Sub
End Module
Dancari
 
Posts: 1
Joined: Fri Nov 18, 2011 1:55 am

Who is online

Users browsing this forum: No registered users and 1 guest