-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcircular-queue.h
More file actions
90 lines (66 loc) · 2.83 KB
/
circular-queue.h
File metadata and controls
90 lines (66 loc) · 2.83 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
#ifndef LAB2_CIRCULAR_QUEUE_H
#define LAB2_CIRCULAR_QUEUE_H
class CircularQueue {
public:
// Defines the kind of data that the queue will contain.
typedef int QueueItem;
// Defines a constant that will be used to indicate an empty queue.
static const QueueItem EMPTY_QUEUE;
private:
// Befriend so tests have access to variables.
friend class CircularQueueTest;
// MEMBER VARIABLES
// An array of queue items.
QueueItem* items_;
// Index of the first element in the circular queue.
unsigned int head_;
// Index of the element after the last item in the circular queue.
unsigned int tail_;
// Maximum number of items in the queue.
unsigned int capacity_;
// Current number of items in the queue.
unsigned int size_;
// Copy constructor. Declared private so we don't use it incorrectly.
CircularQueue(const CircularQueue& other) {}
// Assignment operator. Declared private so we don't use it incorrectly.
CircularQueue operator=(const CircularQueue& other) {}
public:
// CONSTRUCTORS/DESTRUCTOR
// Default constructor of the class CircularQueue. It uses 16 as the
// initial capacity of the array, and allocates the required memory
// space for the queue. The function appropriately initializes the
// fields of the created empty queue.
CircularQueue();
// Parametric constructor of the class CircularQueue. It allocates
// the required memory space for the queue of the given capacity.
// The function appropriately initializes the fields of the created
// empty queue.
CircularQueue(unsigned int capacity);
// Destructor of the class CircularQueue. It deallocates the memory
// space allocated for the queue.
~CircularQueue();
// ACCESSORS
// Returns the number of items in the queue.
unsigned int size() const;
// Returns true if the queue is empty and false otherwise.
bool empty() const;
// Returns true if the queue is full and false otherwise.
bool full() const;
// Returns the value at the front of the queue without removing it
// from the queue. If the queue is empty, it returns the EMPTY_QUEUE
// constant instead.
QueueItem peek() const;
// MUTATORS
// Takes as an argument a QueueItem value. If the queue is not at capacity,
// it inserts the value at the rear of the queue after the last item, and
// returns true. If the insertion fails due to lack of space, it
// returns false.
bool enqueue(QueueItem value);
// Removes the item from the front of the queue and returns it. If the queue
// is empty, it returns the EMPTY_QUEUE constant instead.
QueueItem dequeue();
// Prints the queue items sequentially and in order, from the front
// to the rear of the queue.
void print() const;
};
#endif // LAB2_CIRCULAR_QUEUE_H