Menu

Starter code provided:   import java.util.NoSuchElementException; /**  description of class TwoStackQueue here. * * @author (your name) * @version (a version number or a date) */ public class Two…

Question

Answered step-by-step

Starter code provided: import java.util.NoSuchElementException; /**…

Image transcription text

Two stack queue Although Ar ray Li st data structures are great for creating stacks, we know that they suffer
from 0m) time complexities for queues. However, two ArrayLi st -based stacks are fine for implementing a
queue. In this assignment, you will implement a stack, and then use two stacks to implement a qShow more
Show more

 

Starter code provided:

 

import java.util.NoSuchElementException;

/**
 description of class TwoStackQueue here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class TwoStackQueue<E> implements Queue<E> {
   private Stack<E> back;
   private Stack<E> front;
   
   public TwoStackQueue() {
       back = new StackImpl<E>();
       front = new StackImpl<E>();
   }
   
   public void enqueue(E element) {
     // your code here
     throw new UnsupportedOperationException();
   }
   
   /**
    * This algorithm must be O(1) amortized time complexity!
    * In other words, you should only touch each element 
    * a constant number of times on average.
    */
   public E dequeue() {
     // your code here
     throw new UnsupportedOperationException();
   }

   /**
    * This algorithm must be O(1) amortized time complexity!
    * In other words, you should only touch each element 
    * a constant number of times on average.
    */
   public boolean isEmpty() {
     // your code here
     throw new UnsupportedOperationException();
   }
}
 

OR

Leave a Reply

Your email address will not be published. Required fields are marked *