- 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.03 KB
/
Copy pathSolution.java
File metadata and controls
37 lines (32 loc) · 1.03 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
importjava.io.*;
importjava.util.*;
publicclassSolution {
publicstaticvoidmain(String[] args) {
/* Create and fill Linked List of Integers */
Scannerscan = newScanner(System.in);
intN = scan.nextInt();
LinkedList<Integer> list = newLinkedList();
for (inti = 0; i < N; i++) {
intvalue = scan.nextInt();
list.add(value);
}
/* Perform queries on Linked List */
intQ = scan.nextInt();
for (inti = 0; i < Q; i++) {
Stringaction = scan.next();
if (action.equals("Insert")) {
intindex = scan.nextInt();
intvalue = scan.nextInt();
list.add(index, value);
} else { // "Delete"
intindex = scan.nextInt();
list.remove(index);
}
}
scan.close();
/* Print our updated Linked List */
for (Integernum : list) {
System.out.print(num + " ");
}
}
}