-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaList.java
More file actions
47 lines (30 loc) · 1.1 KB
/
JavaList.java
File metadata and controls
47 lines (30 loc) · 1.1 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
import java.io.*;
import java.util.*;
public class JavaList {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
ArrayList<Integer> list = new ArrayList<>();
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for(int i = 0 ; i < n ; i++){
list.add(sc.nextInt());
}
int query = sc.nextInt();
while(query != 0){
String q = sc.next();
if(q.equals("Insert")){
int x = sc.nextInt();
int y = sc.nextInt();
list.add(x,y);
}
if(q.equals("Delete")) {
int y = sc.nextInt();
list.remove(y);
}
query = query - 1;
}
for(int a : list){
System.out.print(a + " ");
}
}
}