Question: Data structure problem Question 4 : Queue & stack Assume that we have two ADTs. One is a Queue ADT with the following standard operations:

Data structure problem

Question 4 : Queue & stack

Assume that we have two ADTs.

One is a Queue ADT with the following standard operations:

Queue CreateQueue(int x); //Creates a queue with size = x;

void EnQueue(int x, Queue Q); //Insert an integer x to the queue Q.

int DeQueue(); //Removes a queue element and returns it as a result.

The other is a Stack ADT with the following standard operations:

Stack CreateStack(int x); //Creates a stack with size = x;

void Push(int x, Stack S); //Insert an integer x to the stack S.

int Pop(); //Removes the top element of the stack and returns it as a result.

In addition, we also have a Play function below to call the Queue and Stack operations.

void Play( ) {

/* 1*/ Stack S=CreateStack(4);

/* 2*/ Queue Q=CreateQueue(4);

/* 3*/ EnQueue(2, Q);

/* 4*/ EnQueue(3, Q);

/* 5*/ EnQueue(1, Q);

/* 6*/ EnQueue(4, Q);

/* 7*/ Push(DeQueue( ), S);

/* 8*/ Push(DeQueue( ), S);

/* 9*/ EnQueue(Pop( ), Q);

/*10*/ EnQueue(Pop( ), Q);

/*11*/ EnQueue(DeQueue( ), Q);

}

Assume that the front (head) of the queue is on the left. Please write the sequence of values stored in the queue Q after lines 6, 8, 11 in Play() have been executed.

After line 6:

After line 8:

After line 11:

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 Databases Questions!