1: // Created by Frank M. Carrano and Tim Henry.
2: // Copyright (c) 2013 __Pearson Education__. All rights reserved.
4: template<class ItemType>
5: bool ArrayBag<ItemType>::add(const ItemType& newEntry)
6: {
7: bool hasRoomToAdd = (itemCount < maxItems);
8: if (!hasRoomToAdd)
9: {
10: ItemType* oldArray = items;
11: items = new ItemType[2 * maxItems];
12: for (int index = 0; index < maxItems; index++)
13: items[index] = oldArray[index];
14: delete [ ] oldArray;
15: maxItems = 2 * maxItems;
16: } // end if
17: // We can always add the item
18:
19: items[itemCount] = newEntry;
20: itemCount++;
21: return true;
22: } // end ResizableArrayBag add