-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJava-List.java
More file actions
51 lines (45 loc) · 1.35 KB
/
Java-List.java
File metadata and controls
51 lines (45 loc) · 1.35 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
48
49
50
51
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) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
List<Integer> list = new ArrayList<Integer>();
//int[] l = new int[n];
//l = sc.nextInt().split(" ");
for(int i=0;i<n;i++)
{
list.add(sc.nextInt());
}
int q = sc.nextInt();
sc.nextLine();
//int x,y;
for(int i=0;i<2*q;i=i+2)
{
String query = sc.nextLine();
if(query.equals("Insert"))
{
String[] l = sc.nextLine().split(" ");
int x = Integer.parseInt(l[0]);
int y = Integer.parseInt(l[1]);
//sc.nextLine();
list.add(x,y);
}
if(query.equals("Delete"))
{
int x = Integer.parseInt(sc.nextLine());
//sc.nextLine();
//System.out.println(x);
list.remove(x);
}
}
for(int i: list)
{
System.out.print(i+" ");
}
}
}