Answer to Question #78885 in C for Sam

Question #78885
What is the top element in the stack S.
Stack(S); //create a stack S
Queue(Q); //create a queue Q
Push (S,1); Push(S,2);
Push (S,3); Push(S,4);
Enqueue(Q,5); Enqueue(Q,6);
For (i=1) to 4) {
X=Pop (S);
Enqueue(Q,x);
}
For (i=1 to 6) {
Z=Dequeue (Q);
Push(S,x);
}
1
Expert's answer
2018-07-06T05:45:39-0400
There are two possible answers:
1. 1, If in the second cycle there is a misprint ( Z=Dequeue (Q); Push(S,x); ), where Z should be pushed
2. 4, If everything is correct, x is last popped element from previous cycle

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS