Dim skey As Integer
Dim low, high, middle As Integer
Dim found As Boolean
Dim skey1 As String
Dim low1, high1, middlel As Integer
Dim found1 As Boolean
Private Sub cmdNumSearch_Click()
Binary search for Numbers
low = 0
high = 5
found = False
skey = CInt(txtSearch.Text)
Do While found <> True And low <= high
middle = (high + low) / 2
If txtArr (middle). Text < skey Then
low = middle + 1
Elself txtArr(middle).Text > skey Then
high = middle - 1
Else
found = True
End If
Loop
If found = True Then
MsgBox "Element found at:" + CStr(middle + 1)
Else
MsgBox " element not found"
End If
End Sub
Private Sub cmdCharSearch_LostFocus()
For I = 0 To 5
txtArr (I).Text = Clear
Next
End Sub
Private Sub cmdCharSearch_Click()
low1 = 0
high1 = 5
found1 = False
skey1 = txtSearch.Text
Do While found1 <> True And low1 <= high1
middle1 = (high1 + low1) / 2
If txtArr (middle1).Text < skey1 Then
low1 = middle1 + 1
Elself txtArr(middle1).Text > skey1 Then
high1 = middle1 - 1
Else
found1 = True
End If
Loop
If found1 = True Then
MsgBox "Element Found At :" + CStr(CInt(middle1 + 1))
Else
MsgBox "Element Not Found"
End If
End Sub
Private Sub cmdNumSearch_LostFocus()
For I = 0 To 5
txtArr(I).Text = Clear
Next
End Sub
No comments:
Post a Comment