Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Using Entity Relationship Diagrams

Authors: Sikha Saha Bagui, Richard Walsh Earp

3rd Edition

103201718X, 978-1032017181

More Books

Students also viewed these Databases questions