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 ArrayBag<ItemType>::remove(const ItemType& anEntry)
  6: {
  7:    int locatedIndex = getIndexOf(anEntry);
  8:         bool canRemoveItem = !isEmpty() && (locatedIndex > -1);
  9:         if (canRemoveItem)
 10:         {
 11:                 itemCount--;
 12:                 items[locatedIndex] = items[itemCount];
 13:         }  // end if
 14:     
 15:         return canRemoveItem;
 16: }  // end remove