Question
package hw4; import edu.princeton.cs.algs4.Stack; public class StringQueue { //You may NOT add any more fields to this class. private Stack stack1; private Stack stack2; /**
package hw4;
import edu.princeton.cs.algs4.Stack; public class StringQueue { //You may NOT add any more fields to this class. private Stack
/** * Initializes an empty queue. */ public StringQueue() { // TODO }
/** * Returns true if this queue is empty. * * @return {@code true} if this queue is empty; {@code false} otherwise */ public boolean isEmpty() { // TODO return false; }
/** * Returns the number of items in this queue. * * @return the number of items in this queue */ public int size() { // TODO return -1; }
/** * Adds the item to this queue. * * @param item the item to add */ public void enqueue(String item) { // TODO }
/** * Removes and returns the item on this queue that was least recently added. * FOR THIS ASSIGNMENT, YOU MAY ASSUME THAT DEQUEUE IS NEVER CALLED ON AN * EMPTY QUEUE. * * @return the item on this queue that was least recently added */ public String dequeue() { // TODO return null; } }
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