Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL/PHP Database Applications

Authors: Brad Bulger, Jay Greenspan, David Wall

2nd Edition

ISBN: 0764549634, 9780764549632

More Books

Students also viewed these Databases questions

Question

Four common LAN topologies

Answered: 1 week ago