-
Notifications
You must be signed in to change notification settings - Fork 0
/
BCQUEUE.cpp
82 lines (71 loc) · 1.68 KB
/
BCQUEUE.cpp
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
#include <iostream>
#include <queue>
using namespace std;
#define OPERATION_GET_SIZE 1
#define OPERATION_CHECK_EMPTY 2
#define OPERATION_ENQUEUE 3
#define OPERATION_DEQUEUE 4
#define OPERATION_GET_FRONT_ITEM 5
#define OPERATION_GET_BACK_ITEM 6
#define EMPTY_QUEUE -1
queue<int> workingQueue;
int main()
{
int numberOfTestCases;
cin >> numberOfTestCases;
while (numberOfTestCases--)
{
int operation;
cin >> operation;
if (operation == OPERATION_GET_SIZE)
{
cout << workingQueue.size() << endl;
}
if (operation == OPERATION_CHECK_EMPTY)
{
if (workingQueue.empty())
{
cout << "YES" << endl;
}
else
{
cout << "NO" << endl;
}
}
if (operation == OPERATION_ENQUEUE)
{
int newItem;
cin >> newItem;
workingQueue.push(newItem);
}
if (operation == OPERATION_DEQUEUE)
{
if (!workingQueue.empty())
{
workingQueue.pop();
}
}
if (operation == OPERATION_GET_FRONT_ITEM)
{
if (!workingQueue.empty())
{
cout << workingQueue.front() << endl;
}
else
{
cout << EMPTY_QUEUE << endl;
}
}
if (operation == OPERATION_GET_BACK_ITEM)
{
if (!workingQueue.empty())
{
cout << workingQueue.back() << endl;
}
else
{
cout << EMPTY_QUEUE << endl;
}
}
}
}