Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(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

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

Oracle Database Upgrade Migration And Transformation Tips And Techniques

Authors: Edward Whalen ,Jim Czuprynski

1st Edition

0071846050, 978-0071846059

Students also viewed these Databases questions

Question

Consider this article:...

Answered: 1 week ago