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

 //---------------------------------------------------------------------- // LinkedStringLog.java by Dale/Joyce/Weems Chapter 2 // // Implements StringLogInterface

//---------------------------------------------------------------------- // 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

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!