Please visit our sponsor
UNKNOWN
//**************************************
// Name: Binary search
// Description:Binary search algorithm function. Takes an array as an argument and the element
to be searched for in the array. Returns '1' if found, '0' if not.
The code can be modified slightly to return the array index of the found element.
// By: Bhushan Paranjpe
//
//
// Inputs:None
//
// Returns:None
//
//Assumes:None
//
//Side Effects:None
//This code is copyrighted and has limited warranties.
//Please see http://www.Planet-Source-Code.com/xq/ASP/txtCodeId.755/lngWId.8/qx/vb/scripts/ShowCode.htm
//for details.
//**************************************
0)
{$first=$mid+1;}//search the lower half
$mid=($first+$last)/2;//new mid point
}
if(strval(trim($ArrayToSearch[$mid]))==$SearchFor)
//{return $mid;} --> if your objective is to return the index
{return 1;}
else
{return 0;}
//{return -1;} --> if your objective is to return the index
}
?>