home *** CD-ROM | disk | FTP | other *** search
- on BinarySearch thePhrase
- global dataFirst, dataLast
- set first to dataFirst
- set last to dataLast
- set found to 0
- repeat while 1
- if first >= last then
- set found to thePhrase = the name of cast first
- set chop to first
- exit repeat
- end if
- set chop to (first + last) / 2
- set testAgainst to the name of cast chop
- if thePhrase = testAgainst then
- set found to 1
- exit repeat
- end if
- if thePhrase < testAgainst then
- set last to chop - 1
- next repeat
- end if
- set first to chop + 1
- end repeat
- if found then
- return chop
- else
- return -1
- end if
- end
-
- on TestBinarySearch
- set testData to ["range", "opera", "cadenza", "maestro", "a tempo", "the business"]
- repeat with test in testData
- put the number of cast test && BinarySearch(test)
- end repeat
- end
-