list - the list to be searchedtypedef type ItemType
void Search(const ItemType list[],
ItemType item,
int length,
int& index,
Boolean& found)
{
index = 0;
while (index < length && item != list[index])
index++;
found = (index < length);
}
If ItemType is a floating point type, we would need to modify the test in the while loop:
EPSILON is assumed to be defined elsewhere as a global constant.while (index < length && fabs(item - list[index] >= EPSILON)) index++;
Previous page