simont: A picture of me in 2016 (Default)
simont ([personal profile] simont) wrote 2006-06-27 04:33 pm (UTC)

I suppose that'd work, although it seems to me to have a few too many special cases (and to potentially include further loops) for my taste. I preferred my approach: instead of dividing the entire string in half, divide in half the portion of the string which is capable of containing the start point of the needle. If the part of the string after that half-way point contains the needle, then the start point occurs after the half way point. Otherwise, the start point must occur before the half way point, meaning that the first "half" of the string plus (needlelen-1) further characters must contain the needle.

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting