Binary search

long BinarySearch(long left,long right,long value)
{
long i;
long mid = (left+right)/2;

while(left<=right)
{
if(temp[mid]==value)
break;
else if(temp[mid]<value)
left = mid+1;
else
right = mid – 1;

mid = (left+right)/2;
}

return mid;
}

Advertisements