Question: import java.util.Scanner; public class PoD { public static void main( String [] args ) { Scanner in = new Scanner( System.in ); LinkedList teamList =

![[] args ) { Scanner in = new Scanner( System.in ); LinkedList](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f2f55b6ab96_55566f2f55b0f599.jpg)
import java.util.Scanner;
public class PoD
{
public static void main( String [] args )
{
Scanner in = new Scanner( System.in );
LinkedList teamList = new LinkedList();
final int TEAM_SIZE = Integer.valueOf(in.nextLine());
for (int i=0; i { String newTeamMember = in.nextLine(); teamList.append(newTeamMember); } while (in.hasNextInt()) { int task = in.nextInt(); if (task == 0) { teamList.removeHead(); } else if (task == 1) { teamList.removeTail(); } } System.out.println("FINAL TEAM:"); System.out.println(teamList); in.close(); System.out.print("END OF OUTPUT"); } } ---------------------------------------------------------------------------- import java.util.NoSuchElementException; public class LinkedList { //attributes private Node head; private Node tail; //Node class Node { public Object data; public Node previous; public Node next; } /** * Constructs an empty linked list/ */ public LinkedList() { head = null; tail = null; } //PLEASE START WORK HERE //=============================================== /** * @method removeHead() * Remove node from head of the linked list * @returns Object: head node of the linked list */ /** * @method removeTail() * Remove node from tail of the linked list * @returns Object: tail node of the linked list */ //=============================================== //PLEASE END WORK HERE /** * Appends a new node to the end of the linked list. */ public void append(Object element) { if (head == null) //Empty linked list { Node firstNode = new Node(); firstNode.data = element; firstNode.previous = null; firstNode.next = null; head = firstNode; tail = firstNode; } else //At least one node already exists. { Node newNode = new Node(); newNode.data = element; newNode.previous = tail; newNode.next = null; tail.next = newNode; tail = newNode; } } public String toString() { Node position = head; String output = ""; while (position != null) { output += position.data + " "; position = position.next; } return output; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
