class ListInterface
1: // Created by Frank M. Carrano and Timothy M. Henry.
2: // Copyright (c) 2017 Pearson Education, Hoboken, New Jersey.
4: /** Interface for the ADT list
5: Listing 8-1
6: @file ListInterface.h */
8: #ifndef LIST_INTERFACE_
9: #define LIST_INTERFACE_
11: template<class ItemType>
12: class ListInterface
13: {
14: public:
15: /** Sees whether this list is empty.
16: @return True if the list is empty; otherwise returns false. */
17: virtual bool isEmpty() const = 0;
18:
19: /** Gets the current number of entries in this list.
20: @return The integer number of entries currently in the list. */
21: virtual int getLength() const = 0;
22:
23: /** Inserts an entry into this list at a given position.
24: @pre None.
25: @post If 1 <= position <= getLength() + 1 and the insertion is
26: successful, newEntry is at the given position in the list,
27: other entries are renumbered accordingly, and the returned
28: value is true.
29: @param newPosition The list position at which to insert newEntry.
30: @param newEntry The entry to insert into the list.
31: @return True if the insertion is successful, or false if not. */
32: virtual bool insert(int newPosition, const ItemType& newEntry) = 0;
33:
34: /** Removes the entry at a given position from this list.
35: @pre None.
36: @post If 1 <= position <= getLength() and the removal is successful,
37: the entry at the given position in the list is removed, other
38: items are renumbered accordingly, and the returned value is true.
39: @param position The list position of the entry to remove.
40: @return True if the removal is successful, or false if not. */
41: virtual bool remove(int position) = 0;
42:
43: /** Removes all entries from this list.
44: @post The list contains no entries and the count of items is 0. */
45: virtual void clear() = 0;
46:
47: /** Gets the entry at the given position in this list.
48: @pre 1 <= position <= getLength().
49: @post The desired entry has been returned.
50: @param position The list position of the desired entry.
51: @return The entry at the given position. */
52: virtual ItemType getEntry(int position) const = 0;
53:
54: /** Replaces the entry at the given position in this list.
55: @pre 1 <= position <= getLength().
56: @post The entry at the given position is newEntry.
57: @param position The list position of the entry to replace.
58: @param newEntry The replacement entry.
59: @return The replaced entry. */
60: virtual ItemType replace(int position, const ItemType& newEntry) = 0;
61:
62: /** Destroys this list and frees its assigned memory. */
63: virtual ~ListInterface() { }
64: }; // end ListInterface
65: #endif