Created
April 17, 2014 02:01
-
-
Save pisceanfoot/10947988 to your computer and use it in GitHub Desktop.
binary search
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int index = 0; | |
int last = this.array.Length - 1; | |
while (index <= last) | |
{ | |
int mid = index + (last - index) / 2; | |
IPAddressInfo info = this.array[mid]; | |
if (ip >= info.Start && ip <= info.End) | |
{ | |
return info.AreaCode; | |
} | |
else if (ip > info.Start) | |
{ | |
index = mid + 1; | |
} | |
else | |
{ | |
last = mid - 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment