Question: in java please, Implement the following operations of a queue using stacks. push(x) -- Push element x to the back of queue. popo -- Removes
in java please,

Implement the following operations of a queue using stacks. push(x) -- Push element x to the back of queue. popo -- Removes the element from in front of queue. peek() -- Get the front element. empty() -- Return whether the queue is empty. Example: MyQueue queue = new MyQueue(); queue.push(1); queue push(2); queue.peek(); // returns 1 queue .pop); Il returns 1 queue empty(); // returns false Notes: You must use only standard operations of a stack -- which means only push to top, peek/pop from top, size, and is empty operations are valid. You cannot call pop or peek operations on an empty queue. class My Queue /** Initialize your data structure here. */ public My Queue() { /** Push element x to the back of queue. */ public void push(int x) { /** Removes the element from in front of queue and returns that element. */ public int pop0 { /** Get the front element. */ public int peek() { /** Returns whether the queue is empty. */ public boolean empty0 {
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
