-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path03_queue_display.cpp
More file actions
60 lines (47 loc) · 988 Bytes
/
03_queue_display.cpp
File metadata and controls
60 lines (47 loc) · 988 Bytes
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
#include <iostream>
#include <cstdlib>
class Queue {
private:
int* data;
int front;
int rear;
int capacity;
public:
Queue(int size) {
capacity = size;
data = new int[capacity];
front = 0;
rear = -1;
}
~Queue() {
delete[] data;
}
bool isEmpty() {
return front > rear;
}
bool isFull() {
return rear == capacity - 1;
}
void enqueue(int value) {
if (isFull()) return;
data[++rear] = value;
}
void display() {
if (isEmpty()) {
std::cout << "Queue is empty\n";
return;
}
for (int i = front; i <= rear; i++)
std::cout << data[i] << " ";
std::cout << "\n";
}
};
int main(int argc, char* argv[]) {
if (argc < 2) return 1;
int n = std::atoi(argv[1]);
Queue q(n);
for (int i = 2; i < argc; i++)
q.enqueue(std::atoi(argv[i]));
q.display();
return 0;
}