Source of remove.cpp


  1: //  Created by Frank M. Carrano and Timothy M. Henry.
  2: //  Copyright (c) 2017 Pearson Education, Hoboken, New Jersey.

  4: template<class ItemType>
  5: bool ArrayList<ItemType>::remove(int position)
  6: {
  7:    bool ableToRemove = (position >= 1) && (position <= itemCount);
  8:    if (ableToRemove)
  9:    {
 10:       // Remove entry by shifting all entries after the one at
 11:       // position toward the beginning of the array
 12:       // (no shift if position == itemCount)
 13:       for (int pos = position; pos < itemCount; pos++)
 14:          items[pos] = items[pos + 1];
 15:          
 16:       itemCount--;  // Decrease count of entries
 17:    }  // end if
 18:    
 19:    return ableToRemove;
 20: }  // end remove