Question: Start with the following Java code: class Node { private String data; private Node next; public Type getData() { return data; } public Node getNext()

Start with the following Java code:

class Node {

private String data;

private Node next;

public Type getData() {

return data;

}

public Node getNext() {

return next;

}

public void setData(Type data) {

this.data = data;

}

public void setNext(Node next) {

this.next = next;

}

public String toString() {

return "Node: " + getData();

}

}

///////////////////

Modify the code to complete the following conditions:

Start with the following Java code: class Node { private String data;

Update/Modify the LinkList class so that it supports the following operations: void removeFirst- remove the first node of the list. If the list is empty, do nothing. Set the next field of the removed node to null. int size ( ) -return the number of elements (nodes) in the list toString ( ) Size: . Elements: -implement so that the printout should be like the following Node: Node: String getFirst - return the first Node. Return null if empty. Do not remove the node. void addFirst (String data)- Add a node at the beginning of the list with the data passed false. valid (e.g., size is less than n or if n is negative). n is negative or n is greater or equal to size) boolean contains (String target) - return true if target is found, otherwise return . void insertNode (int n, String data) - insert data at nth position. No effect if n is not . void removeNode (int n) - remove the node at nth position. No effect if n is not valid (e.g., set (int n, String data) - set nth node with the new value Provide main() method in the LinkList.java to test your code

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!