-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathJava List
38 lines (36 loc) · 1.01 KB
/
Java List
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
import java.util.Scanner;
import java.util.LinkedList;
public class Solution {
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 a=scan.nextInt();
LinkedList<Integer> list = new LinkedList<>();
for(int i=0;i<a;i++)
{
int value=scan.nextInt();
list.add(value);
}
int x=scan.nextInt();
for(int i=0;i<x;i++)
{
String Inp=scan.next();
if(Inp.equals("Insert"))
{
int index=scan.nextInt();
int value=scan.nextInt();
list.add(index,value);
}
else
{
int index=scan.nextInt();
list.remove(index);
}
}
scan.close();
for(Integer num:list)
{
System.out.print(num+" ");
}
}
}