Question
you are going to be implementing a linked list, while setting up a team roster. Most of the linked list has already been implemented, inlcluding
you are going to be implementing a linked list, while setting up a team roster. Most of the linked list has already been implemented, inlcluding a constructor and append method. You will have to implement a contains method.
import java.util.Scanner;
public class PoD {
public static void main( String [] args ) {
Scanner in = new Scanner( System.in );
LinkedList listOfPlayers = new LinkedList();
final int LIST_SIZE = Integer.valueOf(in.nextLine());
for (int i=0; i listOfPlayers.append(newPlayer); } String checkPlayerStatus = in.nextLine(); if (listOfPlayers.contains(checkPlayerStatus)) { System.out.println(checkPlayerStatus + " is on the team."); } else { System.out.println(checkPlayerStatus + " did not make the team."); } in.close(); System.out.print("END OF OUTPUT"); } } --------------------------------------------------------------------------------------------------- import java.util.NoSuchElementException; /** * A listnked list is a sequence of nodes with efficient element * insertion and removal. This class contains a subset of the methods * of the standard java.util.LinkedList class. * * You will finish off the contains method. */ 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; } /** * 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; } } //PLEASE START WORK HERE //=============================================== /** * Check to see if element is contained * anywhere in the linked list. * @returns boolean: true if contained */ //=============================================== //PLEASE END WORK HERE }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started