A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

部分代码 完整项目见附件
  1. -(int)queryNumber:(NSArray*)aData value:(NSInteger)inter{
  2.     NSInteger left = 0;
  3.     NSInteger right = [aData count];
  4.     while (left <= right){
  5.         NSInteger mid = (left+right)/2;
  6.         if ([[aData objectAtIndex:mid] intValue] < inter){
  7.             left = mid+1;
  8.         }
  9.         else if ([[aData objectAtIndex:mid] intValue] > inter){
  10.             right = mid - 1;
  11.         }
  12.         else{
  13.             NSLog(@"We had found the number %d in array",[[aData objectAtIndex:mid] intValue]);
  14.             return;
  15.         }
  16.     }
  17.     NSLog(@"We couldn't found the number %d in array",inter);
  18.     return;
  19. }
复制代码



lab1.rar

26.66 KB, 下载次数: 75

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马