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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started