You are here: DEVPPL Forum Programming Visual Basic Forum
NOTIFICATIONS
54.121
MEMBERS
15.697
TOPICS
62.285
POSTS
  562
FLASH GAMES
7.740
TUTORIALS
 

Login

E-mail:
Password:

Binary Search Algorithm

0

Loading

Binary Search Algorithm

Postby Dancari » Fri Nov 18, 2011 3: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
 
Reputation: 0
Posts: 1
Joined: Fri Nov 18, 2011 2:55 am
Highscores: 0
Arcade winning challenges: 0

Binary Search Algorithm - Sponsored results

Sponsored results

Login to get rid of ads

 

^ Back to Top