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