-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJava List.java
37 lines (34 loc) · 1.03 KB
/
Java List.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
36
37
/* *
* Author: Pavith Bambaravanage
* URL: https://github.com/Pavith19
* */
/*JAVA-15*/
import java.util.LinkedList;
import java.util.Scanner;
public class Solution {
public static void main(String[] argh){
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
LinkedList<Integer> linkedList = new LinkedList<>();
for (int i = 0; i < n; i++){
int value = scanner.nextInt();
linkedList.add(value);
}
int q = scanner.nextInt();
for (int i = 0; i < q; i++){
String string = scanner.next();
if (string.equals("Insert")){
int index = scanner.nextInt();
int value = scanner.nextInt();
linkedList.add(index, value);
}
else if (string.equals("Delete")){
int index = scanner.nextInt();
linkedList.remove(index);
}
}
for (Integer x : linkedList){
System.out.printf(x+" ");
}
}
}