-
Notifications
You must be signed in to change notification settings - Fork 7
/
queue.cpp
43 lines (32 loc) · 823 Bytes
/
queue.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
// It works on the FIFO methodology
#include <iostream>
#include <queue>
using namespace std;
int main(){
// declaration
queue<int> q;
// assigning values
q.push(1);
q.push(2);
q.push(3);
q.push(4);
q.push(5);
// size of queue
cout<<"The size of queue is "<<q.size()<<endl;
// empty or not
cout<<"Is the queue empty? "<<q.empty()<<endl;
// printing the first element
cout<<"The first element is "<<q.front()<<endl;
// deleting the first element
q.pop();
cout<<"Now after deleting prev first, the first element is "<<q. front()<<endl;
// printing the entire queue
cout<<"Printing the entire queue : ";
int n = q.size();
for(int i=0; i<n; i++){
cout<<q.front()<<" ";
q.pop();
}
cout<<endl;
return 0;
}