【发布时间】:2012-11-29 20:39:13
【问题描述】:
我正在尝试修改我的代码以用于搜索矩形。我的工作代码在下面
for(int i=0;i<[wordRects count];i++){
if(CGRectContainsPoint([[wordRects objectAtIndex:i] CGRectValue], tapedPoint)){
lineImage=[[UIImageView alloc] initWithFrame:[[wordRects objectAtIndex:i]CGRectValue]];
lineImage.backgroundColor=[[UIColor blueColor] colorWithAlphaComponent:0.3f];
[textSelectionView addSubview:lineImage];
break;
}
}
在上面的代码中,wordRects 数组包含大约 500 个矩形,并且 tapedpoint 是视图中的用户点击点。如果用户录制的点不在数组中,那么在最坏的情况下会发生 500 次迭代。 *我的要求 * 我想通过使用二进制搜索算法来减少迭代。是否有任何用途来实现,如果是的话,任何人都可以根据二进制搜索修改我的代码或给我一些想法来实现这个。提前致谢。
【问题讨论】:
标签: iphone objective-c algorithm