部分代码 完整项目见附件- -(int)queryNumber:(NSArray*)aData value:(NSInteger)inter{
- NSInteger left = 0;
- NSInteger right = [aData count];
- while (left <= right){
- NSInteger mid = (left+right)/2;
- if ([[aData objectAtIndex:mid] intValue] < inter){
- left = mid+1;
- }
- else if ([[aData objectAtIndex:mid] intValue] > inter){
- right = mid - 1;
- }
- else{
- NSLog(@"We had found the number %d in array",[[aData objectAtIndex:mid] intValue]);
- return;
- }
- }
- NSLog(@"We couldn't found the number %d in array",inter);
- return;
- }
复制代码
|
|