-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJ10866.java
More file actions
59 lines (53 loc) · 1.82 KB
/
Copy pathJ10866.java
File metadata and controls
59 lines (53 loc) · 1.82 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
package TIL;
import java.util.*;
import java.io.*;
public class J10866 {
public static Deque<Integer> deque;
public static void main(String[] args)throws IOException {
deque = new ArrayDeque<>();
BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
int n =Integer.parseInt(buffer.readLine());
for(int i = 0 ; i <n ; i++) {
String[] input = buffer.readLine().split(" ");
functionDe(input);
}
}
public static void functionDe(String[] input) {
switch(input[0]){
case "push_front":
deque.offerFirst(Integer.parseInt(input[1]));
break;
case "push_back":
deque.offerLast(Integer.parseInt(input[1]));
break;
case "front":
if(deque.isEmpty()){
System.out.println(-1);
} else System.out.println(deque.peekFirst());
break;
case "back":
if(deque.isEmpty()){
System.out.println(-1);
}else System.out.println(deque.peekLast());
break;
case "size":
System.out.println(deque.size());
break;
case "pop_front":
if(deque.isEmpty()){
System.out.println(-1);
}else System.out.println(deque.pollFirst());
break;
case "pop_back":
if(deque.isEmpty()){
System.out.println(-1);
}else System.out.println(deque.pollLast());
break;
case "empty":
if(deque.isEmpty()){
System.out.println(1);
}else System.out.println(0);
break;
}
}
}