What would be the contents of queue Q1 after the following code is executed and
ID: 3574411 • Letter: W
Question
What would be the contents of queue Q1 after the following code is executed and the following data are entered?
Q1 = createQueue
S1 = createStack
while not end of file
read number
if (number not 0)
pushStack (S1, number)
else
popStack (S1, x)
popStack (S1, x)
while S1 is not empty
popStack (S1, x)
enqueue (Q1, x)
endwhile
endif
endwhile
The data are 5, 7, 12, 4, 0, 4, 6, 8, 67, 34, 23, 5, 0, 44, 33, 22, 6, 0.
Please label your stack and queue so that I cannot misinterpret your answer.
This needs to be in python.
Explanation / Answer
Explanation :-
The contents of queue Q1 after the following code is executed and the following data are entered would be
Explanation :-
STEP1 :- read number
STEP2 :- if (number not 0)
STEP3 :- pushStack (S1, number)
STEP4 :- popStack (S1, x)
STEP5:- popStack (S1, x)
STEP6 :- if S1 is not empty
STEP7 :- popStack (S1, x)
STEP8:- enqueue (Q1, x)
5 7 4 6 8 67 44 33
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.