-(void)binary_searchh
{
NSMutableArray* arr = [[NSMutableArray alloc]initWithObjects:@"1",@"2",@"7",@"10",@"45",@"90",nil];
int value = 90;
int min = 0;
int max = 5;
for (int i=0; i<[arr count]; i++)
{
int mid = (min+max)/2;
if(value>[[arr objectAtIndex:mid] integerValue] )
{
min = mid+1;
}
else if(value<[[arr objectAtIndex:mid] integerValue])
{
max = mid -1;
}
else if(value==[[arr objectAtIndex:mid] integerValue])
{
NSLog(@"Found %@",[arr objectAtIndex:mid]);
NSLog(@"Found %d",i);
break;
}
}
}
Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging…!!..iOS App Development Online Training
ReplyDelete