-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path14 queue.cpp
More file actions
66 lines (54 loc) · 1.2 KB
/
14 queue.cpp
File metadata and controls
66 lines (54 loc) · 1.2 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
/*
Implement a Queue as mentioned:
An operation Z is of 2 Types.
1 p (operation of this type means you need to add p in queue)
0 (operation of this type means you need to pop in queue and print the popped element)
Input Format
First line tell the nos. of operation
Second line depicts the operation
Constraints
Explanation:
n the first testcase
1 2 the queue will be {2}
1 3 the queue will be {2 3}
2 poped element will be 2 the queue will be {3}
1 4 the queue will be {3 4}
2 poped element will be 3
Output Format
Print popped elements
Sample Input 0
5
1 2 1 3 0 1 4 0
Sample Output 0
2 3
*/
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<queue>
using namespace std;
queue<int> task;
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int n,choice;
cin>>n;
for (int i=0;i<n;i++)
{
cin>>choice;
if(choice==1)
{
int x;
cin>>x;
task.push(x);
}
else if(choice==0)
{
int y = task.front();
cout<<y<<" ";
task.pop();
}
}
return 0;
}