Esempio n. 1
0
  public static void main(String[] args) {
    // declare the necessary variables
    MyLinkedList balls = new MyLinkedList();

    // declare a Scanner object to read input
    Scanner sc = new Scanner(System.in);

    // read input and process them accordingly
    int noOfBalls = sc.nextInt();

    // create nodes from 1 .... N and store into list
    for (int i = 1; i <= noOfBalls; i++) {
      balls.addLast(i);
    }

    // get the number of operations the user have and iterate
    int operations = sc.nextInt();

    for (int i = 0; i < operations; i++) {
      String mode = sc.next(); // get the mode of operation
      if (mode.equals("A")) {
        balls.doA(sc.nextInt(), sc.nextInt());
      } else if (mode.equals("B")) {
        balls.doB(sc.nextInt(), sc.nextInt());
      } else if (mode.equals("R")) {
        balls.doR(sc.nextInt());
      }
    }

    // print output
    balls.print();
  }