Question: X 1 0 1 7 : Copy Queue to a Stack Use these two interfaces to solve this problem. 1 public interface QueueADT { 2

X1017: Copy Queue to a Stack
Use these two interfaces to solve this problem.
1
public interface QueueADT {
2
public void clear();
3
public boolean enqueue(E it);
4
public E dequeue();
5
public E frontValue();
6
public int numElements();
7
public boolean isEmpty();
8
}
9
10
interface StackADT {
11
public void clear();
12
public boolean push(E it);
13
public E pop();
14
public E topValue();
15
public int numElements();
16
public boolean isEmpty();
17
}
Write a method to remove all of the elements from the 'queue' (one by one) and add them to a newly created stack (use a StackArray) and push the values in the stack. Return this stack. If queue is null, then just return an empty stack. Make sure you use the interfaces from above.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!