void Search(const int list[],
int item,
int length,
int& index,
Boolean& found)
{
index = 0;
while (index < length && item != list[index])
index++;
found = (index < length);
}
You would use the function something like this:
int index; Boolean found; Search(list, 14, 15, index, found); if (found) cout << "14 was found at index: " << index; else cout << "14 was not found";
A picture of an unsorted list is here.
Previous page