Thread: Terminator in integer Array.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #18
    Registered User
    Join Date
    May 2020
    Posts
    23
    Quote Originally Posted by Salem View Post
    > 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;
    }
    Last edited by BillMcEnaney; 06-01-2020 at 02:02 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. integer null terminator
    By vead in forum C Programming
    Replies: 6
    Last Post: 02-11-2018, 08:42 PM
  2. function terminator
    By programmerc in forum C Programming
    Replies: 3
    Last Post: 02-17-2013, 08:08 AM
  3. array and string terminator
    By bobknows in forum C++ Programming
    Replies: 2
    Last Post: 03-08-2011, 07:45 PM
  4. Terminator 4
    By abachler in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 05-23-2009, 11:15 PM
  5. Terminator 3..nope
    By Nutshell in forum A Brief History of Cprogramming.com
    Replies: 30
    Last Post: 07-18-2003, 07:42 AM

Tags for this Thread