![Quote](https://cboard.cprogramming.com/images/misc/quote_icon.png)
Originally Posted by
Salem
> don't know why you need the terminator when you know how many numbers are in the array.
Because that's what the assignment said to use.
I know that, but I wonder purpose the terminator serves when there's already a way to tell whether you've reached the end of the list that the array stores. Why does the teacher want the students to use a terminator then? To speed up a sequential search, I add the target to the end of a list. Then I know that the list contains it when there's another instance of the target before the added one.
Code:
bool contains(int list[], const int target, const int length)
{
register int place = 0;
list[length + 1] = target;
while (list[place] != target)
place++;
return place < length + 1;
}