Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MyLinkedList Class Instance Variables: Head: Node numberOfItems: int Methods: Cr

ID: 3718228 • Letter: M

Question

MyLinkedList Class

Instance Variables:

Head: Node

numberOfItems: int

Methods:

Create a constructor that sets the head to null.

Getters and setters

addNode- This method accepts an Integer value and will add a node to the beginning of the list with the accepted Integer value as its data. Be sure to increase the numberOfItems variable.

addLast- This method accepts an Integer value and will add a node to the end of the list with the accepted Integer value as its data. Be sure to increase the numberOfItems variable. Hint: This method will require a for loop which will take you to the end of the list.

for(curr = head; count < numberOfItems-1; curr = curr.next)Inside the loop, you will increase the count each time through the loop. When the loop concludes, you are at the end of the list and can then add the node.

deleteNode- This method accepts an Integer value and will conduct a search for the node that contains the Integer received as the value of the data within the node. Once it locates the node, it will remove that node. Be sure to decrease the numberOfItems variable.

printItem- This method accepts a Node and will output the data value for that node.

Node Class

            Instance Variables:

data: Integer

next: Node

Methods:

default Constructor: set the value of data to 0 and next to null

Constructor that accepts an Integer data value and sets the next value to null;

Constructor that accepts an Integer data value and a Node.

Getters and setters

Driver Class

Instantiate a LinkedList

Add a series of nodes to the front of the list sending Integer values of your choice

Create a printList method that calls the printItem from the MyLinkedList Class within a for loop, navigating through the list and passing the current node each iteration.

Your driver should remove at least one node and add one node to the end of the list, outputting the list after each action.

Language = java

Explanation / Answer

Please find my implementation.

Output:

Adding 5 items..
Addition of 5 items complete

List Size Now: 5

Printing list: 3 2 1 6 5

Deleting first item

Printing list: 2 1 6 5

List Size Now: 4

Adding 1 item at end of list

Printing list: 2 1 6 5 9

List Size Now: 5

Deleting last item

Printing list: 2 1 6 5

Deleting middle item

Printing list: 2 1 5

Process finished with exit code 0