Game Development Reference
In-Depth Information
// Get number of elements in the vector
int iCount = mvElementVector.size();
// Set the boundaries of our search range
// to the first and last elements (remember that
// the vector indices are 0-referenced... that's
// why we subtract 1 from iCount!)
int iLow = 0;
int iHigh = iCount - 1;
bool found = false;
int i = 0; // the vector index
while ( !found ) {
// use the mid-way point as our index guess
i = iLow + ( ( iHigh - iLow ) / 2 );
if ( x = mvElementVector[i].x ) {
// the guess is correct
return mvElementVector[i].y;
} // end if
if ( x < mvElementVector[i].x ) {
// lower the high boundary to the current guess
iHigh = i - 1;
} else {
// raise the low boundary to the current guess
iLow = i + 1;
} // end if
} // end while
return mvElementVector[i].y;
}
Search WWH ::




Custom Search