forked from Jasmine-21/Java-FOP
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSource.java
More file actions
70 lines (59 loc) · 1.71 KB
/
Source.java
File metadata and controls
70 lines (59 loc) · 1.71 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
67
68
69
70
import java.util.*;
class Source {
public static Deque<Integer> deque = new LinkedList<Integer>();
public static void add_atend(int data) {
deque.addLast(data);
}
public static void add_athead(int data) {
deque.addFirst(data);
}
public static void delete_atend() {
if(deque.isEmpty()){
System.out.println("Not possible");
}else{
deque.removeLast();
}
}
public static void delete_athead() {
if(deque.isEmpty()){
System.out.println("Not possible");
}else{
deque.removeFirst();
}
}
public static int return_head() {
return deque.getFirst();
}
public static int return_tail() {
return deque.getLast();
}
public static void main(String arg[]) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int value;
for (int j = 0; j < n; j++) {
value = in.nextInt();
switch (value) {
case 1:
add_atend(in.nextInt());
break;
case 2:
add_athead(in.nextInt());
break;
case 3:
delete_atend();
break;
case 4:
delete_athead();
break;
case 5:
System.out.println(return_head());
break;
case 6:
System.out.println(return_tail());
break;
}
}
System.out.println(deque);
}
}