Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.0 kB
2
Indexable
Never
package JavaTest2;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class A {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(scanner.nextInt());
        }

        int queryCount = scanner.nextInt();
        for (int i = 0; i < queryCount; i++) {
            String query = scanner.next();
            if (query.equals("Insert")) {
                int index = scanner.nextInt();
                int insertElement = scanner.nextInt();
                list.add(index, insertElement);
            }
            else if (query.equals("Delete")) {
                int deleteIndex = scanner.nextInt();
                list.remove(deleteIndex);
            }
        }
        scanner.close();
        for(int i:list)
        {
        System.out.print(i +" ");
}

    }
}
Leave a Comment