forked from atuldev19/dsa
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathList-Program.java
More file actions
38 lines (33 loc) · 964 Bytes
/
Copy pathList-Program.java
File metadata and controls
38 lines (33 loc) · 964 Bytes
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
# List Program in Java
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
List<Integer> l=new ArrayList<Integer>();
for(int i=0;i<n;i++){
l.add(sc.nextInt());
}
int query=sc.nextInt();
int x,y,dindex;
int[] index=new int[2];
for(int i=0;i<query;i++){
String in=sc.next();
if(in.equals("Insert")){
for(int j=0;j<2;j++)
index[j]=sc.nextInt();
l.add(index[0],index[1]);
}else if(in.equals("Delete")){
dindex=sc.nextInt();
l.remove(dindex);
}
}
Iterator itr=l.iterator();
while(itr.hasNext())
System.out.print(itr.next()+" ");
}
}