Question: 1) Assume you have a Queue class that provides the following public methods: void insert (Object x) // inserts x at back of queue. Object

1) Assume you have a Queue class that provides the following public methods: void insert (Object x) // inserts x at back of queue. Object remove() // removes and returns Object at front // of queue. Object peek() // returns reference to Object at front // of queue without removing it. int size() // returns number of objects in queue. The class stack will implement a stack using the queue. Let the top of the stack always be at the back of the queue, so the bottom of the stack will be at the front of the queue. Fill in the implementations of the methods in the class below: class Stack { private Queue Q; // the queue that stores the data. public Stack() {Q = new Queue (); } public void push(Object data) { 11 assume the stack is not empty when pop is called public Object pop() {
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
