Question: (Java)Use the attached Node class (with String type data) to implement a linked list class, named LL , with the following methods: /*Add newData as

(Java)Use the attached Node class (with String type data) to implement a linked list class, named LL, with the following methods:

/*Add newData as the first element of the LL object. */ public void add(String newData) /* Starting with a Node ptr that is equal to the head Node, concatenate the data of the Node followed by a space to the end of a result string set ptr to the next Node, stopping when ptr is null, then returning the result string. */ public String toString() Write a driver program to declare and instantiate an LL object, then to add each of the first 11 powers of 2 (20, 21, 22, ... , 29, 210) as the first element of the LL, then print out the contents of the LL using it's toString() method.

Node class

public class Node { private String data; private Node next; public Node(String newData) { this.data=newData; // this.next=null; } public Node(String newData, Node newNext) { this.data=newData; this.next=newNext; } public String getData() { return this.data; } public Node getNext() { return this.next; } public void setData(String newData) { this.data = newData; } public void setNext(Node newNext) { this.next = newNext; } }

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!