Wyo VB Lecture Notes
Objective #1: Trace and apply the sequential search algorithm.
Objective #2: Trace and apply the binary search algorithm.
System.Array.Sort(mScores) ' array must be sorted in order for binary search to work
While (Not (found) And low <= high)
If (mScores(mid) = key) Then
found = True
Else
If (mScores(mid) > key) Then
high = mid - 1
ElseIf (mScores(mid) < key) Then
low = mid + 1
End If
mid = Math.Round((low + high) / 2)
End If
End While
If (found = True) Then
lblResult.Text = "Found in position " + Str(mid)
Else
lblResult.Text = "Not Found"
End If
End Sub