Question: Queue and stack 1) Draw the diagram for this as well, and write a few lines of code (it should be pretty short) for b)
Queue and stack
1) Draw the diagram for this as well, and write a few lines of code (it should be pretty short) for b) part.

2) Again, draw the diagram and write the code for b) part.

3) What's the output of the following code? Again, draw the diagram and please explain to me what "line.enqueue (stack.peek())" does?
IntegerStack stack = new IntegerStack ();
IntegerQueue line = new IntegerQueue ();
for ( int num = 1; num
{
stack.push (num);
line.enqueue (stack.peek());
}
for (int num = 1; num
{
line.enqueue(stack.peek());
line.enqueue(line.front());
stack.pop();
line.dequeue();
}
while (!line.isempty())
{
System.out.println(line.front ());
line.dequeue();
}
A queue of integers is implemented using a circular array public class Int@ueue i private int[i data; private int count private int front private int rear; a. Give the output from the following code IntQueue g = new IntQueue(); q.enqueue (5) q.enqueue (15) q.enqueue (110); int val -q.dequeue ) val = q. dequeue ( ) ; q.enqueue (17) q.enqueue (19) enqueue(21); val = g. dequeue ( ) ; encrudeue while Iaemptvueue)) System.outpzint (adegueueO): Output: b. Write the code for the dequeue method using the variables above
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
