-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathJavaList.java
36 lines (31 loc) · 906 Bytes
/
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
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
LinkedList list = new LinkedList();
int n = sc.nextInt();
for(int i = 0; i < n; i ++) {
list.add(sc.nextInt());
}
int q = sc.nextInt();
while(q-- > 0) {
String s = sc.next();
if(s.equals("Insert")) {
int index = sc.nextInt();
int value = sc.nextInt();
list.add(index, value);
} else {
int value = sc.nextInt();
list.remove(value);
}
}
Iterator iterator = list.iterator();
while(iterator.hasNext()) {
System.out.print(iterator.next() + " ");
}
}
}