- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.java
More file actions
Latest commit
37 lines (32 loc) · 1.01 KB
/
Copy pathsolution.java
File metadata and controls
37 lines (32 loc) · 1.01 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
// https://github.com/Utkarsh299-tech
importjava.io.*;
importjava.util.*;
publicclassSolution {
publicstaticvoidmain(String[] args) {
Scannersc = newScanner(System.in);
intN = sc.nextInt();
List<Integer> list = newLinkedList<>();
for(inti = 0; i < N; i++) {
intval = sc.nextInt();
list.add(val);
}
/* Performing queries on LinkedList */
intQ = sc.nextInt();
for(inti = 0; i < Q; i++) {
Stringquery = sc.next();
if(query.equals("Insert")) {
intindex = sc.nextInt();
intvalue = sc.nextInt();
list.add(index, value);
} else { // if query.equals("Delete")
intindex = sc.nextInt();
list.remove(index);
}
}
sc.close();
/* Printing the updated list */
for(Integernum : list) {
System.out.print(num + " ");
}
}
}