class ArrayList
1: // Created by Frank M. Carrano and Tim Henry.
2: // Copyright (c) 2013 __Pearson Education__. All rights reserved.
4: /** ADT list: Array-based implementation.
5: Listing 9-1.
6: @file ArrayList.h */
8: #ifndef _ARRAY_LIST
9: #define _ARRAY_LIST
11: #include "ListInterface.h"
12: #include "PrecondViolatedExcep.h"
14: template<class ItemType>
15: class ArrayList : public ListInterface<ItemType>
16: {
17: private:
18: static const int DEFAULT_CAPACITY = 5; // Small capacity to test for a full list
19: ItemType items[DEFAULT_CAPACITY]; // Array of list items
20: int itemCount; // Current count of list items
21: int maxItems; // Maximum capacity of the list
22:
23: public:
24: ArrayList();
25: // Copy constructor and destructor are supplied by compiler
26:
27: bool isEmpty() const;
28: int getLength() const;
29: bool insert(int newPosition, const ItemType& newEntry);
30: bool remove(int position);
31: void clear();
32:
33: /** @throw PrecondViolatedExcep if position < 1 or
34: position > getLength(). */
35: ItemType getEntry(int position) const throw(PrecondViolatedExcep);
37: /** @throw PrecondViolatedExcep if position < 1 or
38: position > getLength(). */
39: void setEntry(int position, const ItemType& newEntry)
40: throw(PrecondViolatedExcep);
41: }; // end ArrayList
43: #include "ArrayList.cpp"
44: #endif