Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

//---------------------------------------------------------------------- // LinkedStringLog.java by Dale/Joyce/Weems Chapter 2 // // Implements StringLogInterface using a linked list // of LLStringNode to hold the log strings. // ajg

image text in transcribed

//---------------------------------------------------------------------- // LinkedStringLog.java by Dale/Joyce/Weems Chapter 2 // // Implements StringLogInterface using a linked list // of LLStringNode to hold the log strings. // ajg version: formatting; private; while->for; if //---------------------------------------------------------------------- package ch02.stringLogs; public class LinkedStringLog implements StringLogInterface { private String name; // name of this StringLog private LLStringNode log = null ; // reference to the first node of // linked list holding the strings // Create an empty StringLog object with name "name". public LinkedStringLog(String name) { this.name = name; } public void insert(String element) { // Precondition: This StringLog is not full. LLStringNode newNode = new LLStringNode(element); newNode.setLink(log); log = newNode; } public boolean isFull() { return false; } // Return the number of Strings in this StringLog. public int size() { int count = 0; for (LLStringNode node=log; node!=null; node=node.getLink()) count++; return count; } public boolean contains(String element) { // Ignore case difference when doing string comparison. for (LLStringNode node=log; node!=null; node=node.getLink()) if (element.equalsIgnoreCase(node.getInfo())) // they match return true; return false; } public void clear() { log = null; } public String getName() { return name; } // Return a nicely formatted string representing this StringLog. public String toString() { String ans = "Log: " + name + " "; int count = 0; for (LLStringNode node=log; node!=null; node=node.getLink()) ans += (++count) + ". " + node.getInfo() + " "; return ans; } } 

============================================

//LLStringNode.java

public class LLStringNode { private String info; private LLStringNode link; //self-referential class example

public LLStringNode(String info) { this.info = info; link = null; }

public void setInfo(String info) // Sets info string of this LLStringNode. { this.info = info; }

public String getInfo() // Returns info string of this LLStringNode. { return info; }

public void setLink(LLStringNode link) // Sets link of this LLStringNode. { this.link = link; }

public LLStringNode getLink() // Returns link of this LLStringNode. { return link; } }

51. Design and code a new method to be exported from LinkedStringLog called smal lest, with the following signature: public String sllest () The method returns the smallest string in the StringLog. By "smallest," we mean in terms of the lexicographic ordering supported by the St ring class's compar e To method. As a precondition you should assume that the StringLog is not empty

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_2

Step: 3

blur-text-image_3

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

Beginning PostgreSQL On The Cloud Simplifying Database As A Service On Cloud Platforms

Authors: Baji Shaik ,Avinash Vallarapu

1st Edition

1484234464, 978-1484234464

More Books

Students also viewed these Databases questions

Question

3. Comment on how diversity and equality should be managed.

Answered: 1 week ago

Question

describe the legislation that addresses workplace equality

Answered: 1 week ago