-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.cpp
More file actions
52 lines (39 loc) · 1.08 KB
/
queue.cpp
File metadata and controls
52 lines (39 loc) · 1.08 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
/*
queue.cpp
Author: Rhea Koparde
Short description of this file:
creates the list of positions that will store a position
when it is explored
*/
#include "queue.h"
// constructor. maxlen must be as large as the total number
// of Locations that will ever be entered into this Queue.
// this is complete, you don't need to change it.
Queue::Queue(int maxlen) {
contents = new Location[maxlen];
head = 0;
tail = 0;
}
// destructor. releases resources. C++ will call it automatically.
// this is complete, you don't need to change it.
Queue::~Queue() {
delete[] contents;
}
// insert a new Location at the end/back of our list
void Queue::add_to_back(Location loc) {
// FILL THIS IN
contents[tail].row=loc.row;
contents[tail].col=loc.col;
tail++;
}
// return and "remove" the oldest Location not already extracted
Location Queue::remove_from_front() {
// FILL THIS IN
head++;
return contents[head-1];
}
// is this Queue empty? (did we extract everything added?)
// this is complete, you don't need to change it.
bool Queue::is_empty() {
return head == tail;
}