forked from anubhav100rao/codeplus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue_stl.cpp
38 lines (25 loc) · 795 Bytes
/
queue_stl.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
#include<bits/stdc++.h>
using namespace std;
int main() {
// operations allowed
// queue.push(el) adds el in the back
// queue.front() returns element present at front of q
// queue.pop() removes first element of queue
queue<int>q;
q.push(1);
q.push(2);
q.push(3);
// this is also ok queue<int>q({1, 2, 3});
cout << q.front() << "\n";
q.pop();
cout << q.front() << "\n";
while(!q.empty()) {
cout << q.front() << "\n";
q.pop();
}
// note: we also have queue.back() function to get the last element of queue, but we use it rarely
q.push(1);
q.push(2);
q.push(3);
cout << q.front() << " " << q.back() << "\n"; // can you guess the output 🚀🚀
}