-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.cpp
More file actions
299 lines (253 loc) · 7.87 KB
/
list.cpp
File metadata and controls
299 lines (253 loc) · 7.87 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
/***************************************************************
* Name : List
* Author : Evan Bunnell
* Created : 5/4/2023
***************************************************************/
#include "list.h"
#include <iostream>
#include <iomanip>
#include <cstddef>
using namespace std;
const int MAX_TANK = 2;
const int MAX_HEAL = 2;
const int MAX_DPS = 2;
/**************************************************************
* Name: Character
* Description: Default no-arg constructor
* Input parameters: none
***************************************************************/
List::List() {
tank = 0;
healer = 0;
dps = 0;
}
/***************************************************************
* Class Functions
***************************************************************/
/**************************************************************
* Name: insert
* Description: Handles initial placement of object in the queue
* and increments appropriate role variable
* Input: Character
* Output: n/a
***************************************************************/
void List::insert(Character character) {
//iterate counters up
if (character.getRole() == "tank") {
++tank;
}
if (character.getRole() == "healer") {
++healer;
}
if (character.getRole() == "dps") {
++dps;
}
emplace(character);
}
/**************************************************************
* Name: emplace
* Description: Emplaces object into queue
* Input: Character
* Output: n/a
***************************************************************/
void List::emplace(Character character) {
Node *temp, *curr, *pre = NULL;
temp = new Node;
temp->character = character;
if (front == NULL or character.priority < front->character.priority) {
temp->next = front;
front = temp;
}
else {
curr = front;
while (curr and character.priority >= curr->character.priority) {
pre = curr;
curr = curr->next;
}
temp->next = pre->next;
pre->next = temp;
}
}
/**************************************************************
* Name: search
* Description: Searches for object in queue by name
* Input: String
* Output: Boolean
***************************************************************/
bool List::search(string name) {
if (front == NULL) {
return 0;
}
else {
Node *curr;
curr = front;
for (int i = 0; i < size(); i++) {
if (curr->character.getName() == name) {
return 1;
}
curr = curr->next;
}
return 0;
}
}
/**************************************************************
* Name: Delete
* Description: Deletes object from queue after search() confirms
* existence
* Input: String
* Output: n/a
***************************************************************/
void List::Delete(string name) {
if (front == NULL) {
return;
}
else {
Node *curr, *pre;
curr = front;
while (curr->character.getName() != name) {
pre = curr;
curr = curr->next;
}
if (curr->character.priority == 1 || curr->character.priority == 4) {
--tank;
}
if (curr->character.priority == 2 || curr->character.priority == 5) {
--healer;
}
if (curr->character.priority == 3 || curr->character.priority == 6) {
--dps;
}
cout << "\nDeleted character: " << curr->character.getName() << endl;
if (curr == front) {
front = curr->next;
}
else pre->next = curr->next;
free (curr);
}
}
/**************************************************************
* Name: display
* Description: Cycles through queue and calls Character print()
* function per object, numbers list
* Input: n/a
* Output: Numbered list of all objects
***************************************************************/
void List::display() {
if (front == NULL){
cout << "\nRoster is empty." << endl;
return;
}
Node *curr = front;
cout << "\nCurrently signed up: " << endl;
int counter = 1;
while (curr) {
cout << setfill('0') << setw(2) << counter << ". ";
++counter;
curr->character.print();
curr = curr->next;
}
cout << endl;
return;
}
/**************************************************************
* Name: size
* Description: Function for determining size of queue
* Input: n/a
* Output: Int
***************************************************************/
int List::size() {
int size = 0;
if (front == NULL)
cout << "Roster is empty." << endl;
Node *curr = front;
while (curr) {
++size;
curr = curr->next;
}
return size;
}
/**************************************************************
* Name: sort
* Description: Sorts list and changes priority based on MAX
* variables
* Input: n/a
* Output: n/a
***************************************************************/
void List::sort() {
int tCount = 0, hCount = 0, dCount = 0;
Node *curr, *pre;
curr = front;
//cout << "Tanks: " << tank << endl << "Healers: " << healer << endl << "DPS: " << dps << endl; //FOR TESTING PURPOSES ONLY
if (tank > MAX_TANK) {
while (curr and curr->character.priority <= 1) {
if (curr->character.priority == 1) ++tCount;
if (tCount > MAX_TANK) {
curr->character.priority += 3;
emplace(curr->character);
pre->next = curr->next;
}
pre = curr;
curr = curr->next;
}
}
else rePrio();
if (healer > MAX_HEAL) {
while (curr and curr->character.priority <= 2) {
if (curr->character.priority == 2) ++hCount;
if (hCount > MAX_HEAL) {
curr->character.priority += 3;
emplace(curr->character);
pre->next = curr->next;
}
pre = curr;
curr = curr->next;
}
}
if (dps > MAX_DPS) {
while (curr and curr->character.priority <= 3) {
if (curr->character.priority == 3) ++dCount;
if (dCount > MAX_DPS) {
curr->character.priority += 3;
emplace(curr->character);
pre->next = curr->next;
}
pre = curr;
curr = curr->next;
}
}
}
/**************************************************************
* Name: rePrio()
* Description: Iterates through queue, searches for priority
* of 4 or higher (denoting extra players), and re-prioritizes
* them to a starting priority, 1, 2, or 3.
* Input: n/a
* Output: n/a
***************************************************************/
void List::rePrio() {
Node *curr, *pre;
curr = front;
while (curr and curr->character.priority <= 3) {
pre = curr;
curr = curr->next;
}
while (curr and curr->character.priority >= 4) {
if (tank <= MAX_TANK && tank > 0 && curr->character.priority == 4) {
curr->character.priority -= 3;
emplace(curr->character);
pre->next = curr->next;
}
if (healer <= MAX_HEAL && healer > 0 && curr->character.priority == 5) {
curr->character.priority -= 3;
emplace(curr->character);
pre->next = curr->next;
}
if (dps <= MAX_DPS && dps > 0 && curr->character.priority == 6) {
curr->character.priority -= 3;
emplace(curr->character);
pre->next = curr->next;
}
pre = curr;
curr = curr->next;
}
}