Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; search a sorted array
- Func _Search(ByRef $Array, $Element)
- Local $a = UBound($Array, 1), $b = Int($a/2), $c = 0, $d = 1, $i
- For $i = 1 To Int($a/2) Step 1 ; to prevent infinite loops
- If ($Element = $Array[$b+($c*$d)]) Then
- Return $b+($c*$d)
- ElseIf ($Element > $Array[$b+($c*$d)]) Then
- $b += ($c*$d)
- $c = Int($b/2)
- $d = 1
- Else
- $b += ($c*$d)
- $c = Int($b/2)
- $d = -1
- EndIf
- Next
- Return -1
- EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement