-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathBCQUEUE-src.cpp
93 lines (78 loc) · 1.99 KB
/
BCQUEUE-src.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
83
84
85
86
87
88
89
90
91
92
93
import java.util.Scanner;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author sev_user
*/
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int c, x = 0;
Queue q = new Queue();
for (int i = 1; i <= n; i++){
c = sc.nextInt();
if (c == 3) x = sc.nextInt();
switch (c) {
case 1: {
System.out.println(q.size());
break;
}
case 2: {
if (q.empty()) System.out.println("YES");
else System.out.println("NO");
break;
}
case 3: {
q.push(x);
break;
}
case 4: {
if (!q.empty()) q.pop();
break;
}
case 5: {
if (q.empty()) System.out.println("-1");
else System.out.println(q.front());
break;
}
case 6: {
if (q.empty()) System.out.println("-1");
else System.out.println(q.back());
break;
}
}
}
}
}
class Queue{
public int l, r;
public int q[] = new int [20000];
Queue(){
l = 1;
r = 0;
}
public void push(int v){
q[++r] = v;
}
public int pop(){
int v = q[l++];
return v;
}
public boolean empty(){
return (l > r);
}
public int front(){
return q[l];
}
public int back(){
return q[r];
}
public int size(){
return (r - l + 1);
}
}