-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathJavaList.java
35 lines (31 loc) · 1.03 KB
/
JavaList.java
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 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. */
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
List<Integer> list = new ArrayList<Integer>();
for (int i = 0; i < n; i++) {
list.add(scan.nextInt());
}
int q = scan.nextInt();
scan.nextLine();
for (int j = 0; j < q; j++) {
String operation = scan.nextLine();
if (operation.equals("Insert")) {
list.add(scan.nextInt(), scan.nextInt());
}
else if (operation.equals("Delete")) {
list.remove(scan.nextInt());
}
if(j != q-1){
scan.nextLine();
}
}
// Printing the list
for (int k = 0; k < list.size(); k++) {
System.out.printf("%d ", list.get(k));
}
scan.close();
}
}