-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlist.java
More file actions
35 lines (31 loc) · 943 Bytes
/
list.java
File metadata and controls
35 lines (31 loc) · 943 Bytes
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
import java.util.*;
public class list {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
List<Integer> lst = new ArrayList<>();
for (int i = 0; i < N; i++) {
lst.add(sc.nextInt());
}
int Q = sc.nextInt();
while (Q-- > 0) {
switch (sc.next()) {
case "Insert":
lst.add(sc.nextInt(), sc.nextInt());
break;
case "Delete":
lst.remove(sc.nextInt());
break;
default:
System.out.println("Invalid operation.");
System.exit(-1);
break;
}
}
sc.close();
while (!lst.isEmpty()) {
System.out.print(lst.remove(0) + " ");
}
}
}