Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

AT&T LTE tot onderkant dat 23%O method should always turn the alphabetically in the were comparing the compared of the Series .compare th sound qualand

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
AT&T LTE tot onderkant dat 23%O method should always turn the alphabetically in the were comparing the compared of the Series .compare th sound qualand ga m es dimet doucement All needed classes below: able interface list para se the ring to add Te Wher e are more el satu eres these e more element we one String free the work it and return it. . There most be at least one element in the work private se data ! Each ode has a stris... para thebata the string to wore in this mode Mode the...) pable String getData . Access for the link to the rest Mode ble det private Mode l s The cop in the stak - Push String top of this stack puble voldi ta Test whether this stack has more elements. his would be called only the stock the poduring puble Surin re method dictly to www you want to reme, you tana s AT&T LTE 8:38 PM & 23%D a. Write a class Queue that implements the Worklist interface, using a first-in- first-out order. Implement your Queue using a linked list. b. Write a class PriorityQueue that implements the Worklist interface. No matter in what order strings are added with the add method, the remove method should always return the alphabetically first string still in the worklist. (To compare two strings alphabetically, use the compare To method of the String class. s.compareTo (r) is less than zero if scomes before r, equal to zero if s and rare equal, and greater than zero if scomes after r.) You need not implement a high-efficiency data structure, an implementation using linked lists will do. All needed classes below: public interface Worklist { Add one String to the worklist. * @param item the String to add void add(String item); + Test whether there are more elements in the * worklist; that is, test whether more elements have * been added than have been removed. * @return true if there are more elements boolean hasMore(); * Remove one String from the worklist and return it. * There must be at least one element in the worklist. * @return the String item removed * String remove(); public class Node { private String data; // Each node has a string... private Node link; 11 ...and a link to the next Node . Node constructor. * @param theData the String to store in this Node * @param theLink a link to the next Node public Node (String theData, Node theLink) { data-theData; link = theLink; public class Node { private String data; // Each node has a string... private Node link; 11 ... and a link to the next Node Node constructor. * @param the Data the String to store in this Node * @param theLink a link to the next Node # / public Node (String theData, Node theLink) { data = theData; link - theLink; - Accessor for the String data stored in this Node. * @return our String item public String getData() { return data; + Accessor for the link to the next Node. * @return the next Node public Node getLink() { return link; public class Stack implements Worklist { private Node top - null; // The top Node in the stack . Push a String on top of this stack. * @param data the String to add public void add (String data) { top = new Node (data, top); Test whether this stack has more elements. @return true if this stack is not empty public boolean hasMore() { return (top != null); Pop the top String from this stack and return it. * This should be called only if the stack is not empty. * @return the popped String public String getData return data; i Accessor for the link to the next Node. * @return the next Node */ public Node getLink() { return link; public class Stack implements Worklist { private Node top = null; // The top Node in the stack + Push a String on top of this stack. * @param data the String to add public void add(String data) { top = new Node (data, top); + Test whether this stack has more elements. * @return true if this stack is not empty */ public boolean hasMore() { return (top != null); * Pop the top String from this stack and return it. * This should be called only if the stack is not empty. * @return the popped String . public String remove() { Node n = top; top - n.getLink(); return n.getData(); You may modify the Node class if necessary, but do not change it in a way that breaks the original Stack class. You will need to write some code to test your classes. You can implement Driver-type classes to test your code, as in Chapter 13. An alternative is to add a main method directly to each class you want to test. For example, if you add the following method to the Stack class, you can then run Stack as an application and check that the strings come out in stack order: AT&T LTE tot onderkant dat 23%O method should always turn the alphabetically in the were comparing the compared of the Series .compare th sound qualand ga m es dimet doucement All needed classes below: able interface list para se the ring to add Te Wher e are more el satu eres these e more element we one String free the work it and return it. . There most be at least one element in the work private se data ! Each ode has a stris... para thebata the string to wore in this mode Mode the...) pable String getData . Access for the link to the rest Mode ble det private Mode l s The cop in the stak - Push String top of this stack puble voldi ta Test whether this stack has more elements. his would be called only the stock the poduring puble Surin re method dictly to www you want to reme, you tana s AT&T LTE 8:38 PM & 23%D a. Write a class Queue that implements the Worklist interface, using a first-in- first-out order. Implement your Queue using a linked list. b. Write a class PriorityQueue that implements the Worklist interface. No matter in what order strings are added with the add method, the remove method should always return the alphabetically first string still in the worklist. (To compare two strings alphabetically, use the compare To method of the String class. s.compareTo (r) is less than zero if scomes before r, equal to zero if s and rare equal, and greater than zero if scomes after r.) You need not implement a high-efficiency data structure, an implementation using linked lists will do. All needed classes below: public interface Worklist { Add one String to the worklist. * @param item the String to add void add(String item); + Test whether there are more elements in the * worklist; that is, test whether more elements have * been added than have been removed. * @return true if there are more elements boolean hasMore(); * Remove one String from the worklist and return it. * There must be at least one element in the worklist. * @return the String item removed * String remove(); public class Node { private String data; // Each node has a string... private Node link; 11 ...and a link to the next Node . Node constructor. * @param theData the String to store in this Node * @param theLink a link to the next Node public Node (String theData, Node theLink) { data-theData; link = theLink; public class Node { private String data; // Each node has a string... private Node link; 11 ... and a link to the next Node Node constructor. * @param the Data the String to store in this Node * @param theLink a link to the next Node # / public Node (String theData, Node theLink) { data = theData; link - theLink; - Accessor for the String data stored in this Node. * @return our String item public String getData() { return data; + Accessor for the link to the next Node. * @return the next Node public Node getLink() { return link; public class Stack implements Worklist { private Node top - null; // The top Node in the stack . Push a String on top of this stack. * @param data the String to add public void add (String data) { top = new Node (data, top); Test whether this stack has more elements. @return true if this stack is not empty public boolean hasMore() { return (top != null); Pop the top String from this stack and return it. * This should be called only if the stack is not empty. * @return the popped String public String getData return data; i Accessor for the link to the next Node. * @return the next Node */ public Node getLink() { return link; public class Stack implements Worklist { private Node top = null; // The top Node in the stack + Push a String on top of this stack. * @param data the String to add public void add(String data) { top = new Node (data, top); + Test whether this stack has more elements. * @return true if this stack is not empty */ public boolean hasMore() { return (top != null); * Pop the top String from this stack and return it. * This should be called only if the stack is not empty. * @return the popped String . public String remove() { Node n = top; top - n.getLink(); return n.getData(); You may modify the Node class if necessary, but do not change it in a way that breaks the original Stack class. You will need to write some code to test your classes. You can implement Driver-type classes to test your code, as in Chapter 13. An alternative is to add a main method directly to each class you want to test. For example, if you add the following method to the Stack class, you can then run Stack as an application and check that the strings come out in stack order

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

Murach's SQL Server 2012 For Developers

Authors: Bryan Syverson, Joel Murach, Mike Murach

1st Edition

1890774693, 9781890774691

Students also viewed these Databases questions

Question

=+beliefs about the brand, product, or service?

Answered: 1 week ago

Question

=+4. Did your message properly reflect the brand's image?

Answered: 1 week ago