title: Array-Based List - Insert Function
body: <p>I have implemented the following insert function in my code along with a find function, </p>
  
  <pre><code>template &lt;class Elem&gt;
  bool AList&lt;Elem&gt;::insert(const Elem&amp; item) 
  {
      if (listSize == maxSize) return false;
  
      for (int i = listSize; i &gt; fence; i--)
      {
          listArray[i] = listArray[i - 1];
      }
  
      listArray[fence + 1] = item;
      listSize++; 
      return true;
  }
  bool find(const Elem&amp; item) 
  {
      for (int i = 0; i &lt; getSize(); i++)
          if (listArray[i].getCode() == item.getCode()) 
              return true;
    return false;       
  }
  void print()
  {
      for (int i = 1; i &lt; listSize; i++)
          listArray[i].print();
  }
  void insertMajor(AList&lt;Major&gt; &amp;t, Major &amp;m)
  {
      if (t.find(m))
         cout &lt;&lt; "The major already exists!" &lt;&lt; endl;
      else
         t.insert(m); //inserting major
  }
  </code></pre>
  
  <p>I have then created 3 objects of a class major, and made a list of those majors, however when I "cout" the list, M1 is missing.</p>
  
  <pre><code>AList&lt;Major&gt; list(5);
  Major M1("ECE", "Electrical Engineering");
  Major M2("CCE", "Computer Engineering");
  Major M3("MATH", "Mathematics");
  
  insertMajor(list, M1);
  insertMajor(list, M2);
  insertMajor(list, M3);
  
  cout &lt;&lt; "The list contains " &lt;&lt; list.getSize() &lt;&lt; " majors." &lt;&lt; endl;
  cout &lt;&lt; "--------------- \n";
  list.print();
  cout &lt;&lt; "--------------- \n";
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>The list contains 3 majors.
  --------------- 
  
  Major Code: MATH
  Major Description: Mathematics
  Major Code: CCE
  Major Description: Computer Engineering
  --------------- 
  </code></pre>
  
  <p>I tried finding out why it seems to swallow the first element in the list, but I can't seem to figure it out. Could anyone enlighten me?</p>
  
  <p>Kind Regards</p>