-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathList.h
More file actions
127 lines (105 loc) · 3.89 KB
/
List.h
File metadata and controls
127 lines (105 loc) · 3.89 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//
// Created by Toby Dragon on 9/30/16.
// Generic list interface
//
#ifndef COMP220_LIST_H
#define COMP220_LIST_H
#include <stdexcept>
#include <string>
class List {
private:
//Private to disable copying and assigning from outside class, don't implement these methods
List(const List& listToCopy);
List& operator=(const List& listToCopy);
public:
//constructor
List() {}
//Destructor
virtual ~List() {}
/**
* appends the new item to the end of the list
* @post the list has an additional value in it, at the end
*/
virtual void insertAtEnd(int itemToAdd)=0;
/**
* gets a value from the list
* @param index the location from which to get the value
* @return a copy of the item at index
* @throws out_of_range exception if index is invalid
*/
virtual int getValueAt(int index)=0;
/**
* gives a string representation of the current list
* @returns a string representing the given list in the exact format shown below
* {1, 2, 3, 4, 5}
*/
virtual std::string toString()=0;
/**
* checks if there are any valid items in the list
* @return true if there are no valid items in the list, false otherwise
*/
virtual bool isEmpty()=0;
/**
* returns a count of valid items currently in the list
* @returns the number of valid items in the list
*/
virtual int itemCount()=0;
/**
* makes the list empty of valid items
* @post the list is empty, such that isEmpty() == true
*/
virtual void clearList()=0;
/**
* Searches an int array for a certain value
* @return the index of the first occurrence of numToFind if it is present, otherwise returns -1
*/
virtual int find(int numToFind)=0;
/**
* Searches an int array for a certain value
* @return the index of the last occurrence of numToFind if it is present, otherwise returns -1
*/
virtual int findLast(int numToFind)=0;
/**
* finds the largest value in the array
* @return the first index of the maximum value
* @throws out_of_range exception if there is no item to remove
*/
virtual int findMaxIndex()=0;
/**
* appends the new item to the beginning of the list
* @post the list has an additional value in it, at the beginning
* all other items are shifted down by one index
*/
virtual void insertAtFront(int itemToAdd)=0;
/**
* inserts the item into the list so that it can be found with get(index)
* @param index the location in which to insert this item
* @post the list has an additional value in it at the specified index,
* all further values have been shifted down by one index
* @throws out_of_range exception if index is invalid (< 0 or > currSongCount)
*/
virtual void insertAt(int itemToAdd, int index)=0;
/**
* removes the item at the end of the list, and returns a copy of that item
* @post the item at the end is removed from the list
* @return a copy of the item at the end
* @throws out_of_range exception if there is no item to remove
*/
virtual int removeValueAtEnd()=0;
/**
* removes the item at the front of the list, and returns a copy of that item
* @post the item at the front is removed from the list, everything else is shifted down one
* @return a copy of the item at index
* @throws out_of_range exception if there is no item to remove
*/
virtual int removeValueAtFront()=0;
/**
* removes the item at index from the list, and returns a copy of that item
* @param index the location from which to get the value
* @post the item at index is removed from the list, everything else is shifted down one
* @return a copy of the item at index
* @throws out_of_range exception if index is invalid
*/
virtual int removeValueAt(int index)=0;
};
#endif //COMP220_LIST_H