- import java.util.Scanner;
- import java.util.LinkedList;
- public class Solution {
- public static void main(String[] args) {
- /* Create and fill Linked List of Integers */
- Scanner scan =new Scanner(System.in);
- intN = scan.nextInt();
- LinkedList list = newLinkedList<>();
- for(inti = 0; i < N; i++) {
- intvalue = scan.nextInt();
- list.add(value);
- }
- /* Perfrom queries on Linked List */
- intQ = scan.nextInt();
- for(inti = 0; i < Q; i++) {
- String action = 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 (Integer num : list) {
- System.out.print(num + " ");
- }
- }
- }
来源: http://www.bubuko.com/infodetail-1983759.html