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

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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!