Question: Consider the following stack: + - - - - + | 1 6 | < - top + - - - - + | 2
Consider the following stack:
top
bottom
Of the functions below, which ones return a stack whose contents match the stack depicted above?
There might be more than one correct answer. Be sure to select all that apply.
functionA
Stack functionA
Stack s;
spush;
spush;
spush;
spush;
return s;
functionB
Note: This function is identical to functionA except the
initial four values are pushed in a different order.
Stack functionB
Stack s;
spush;
spush;
spush;
spush;
return s;
functionC
Stack functionC
Stack s;
spush;
spush;
spush;
spush;
speek;
speek;
speek;
speek;
return s;
functionD
Note: This function is identical to functionC except the
initial four values are pushed in a different order.
Stack functionD
Stack s;
spush;
spush;
spush;
spush;
speek;
speek;
speek;
speek;
return s;
functionE
Stack functionE
Stack s;
spush;
spush;
spush;
spush;
spop;
spop;
spop;
spop;
return s;
functionF
Note: This function is identical to functionE except the
initial four values are pushed in a different order.
Stack functionF
Stack s;
spush;
spush;
spush;
spush;
spop;
spop;
spop;
spop;
return s;
functionG
Stack functionG
Stack s;
spush;
spush;
spush;
spush;
The return value from speek is pushed onto s
spushspeek;
return s;
functionH
Note: This function is identical to functionG except the
initial four values are pushed in a different order.
Stack functionH
Stack s;
spush;
spush;
spush;
spush;
The return value from speek is pushed onto s
spushspeek;
return s;
functionI
Stack functionI
Stack s;
spush;
spush;
spush;
spush;
The return value from spop is pushed onto s
spushspop;
return s;
functionJ
Note: This function is identical to functionI except the
initial four values are pushed in a different order.
Stack functionJ
Stack s;
spush;
spush;
spush;
spush;
The return value from spop is pushed onto s
spushspop;
return s;
functionK
Stack functionK
Stack s;
Stack s;
spush;
spush;
spush;
spush;
while sisEmpty
Pop value from s and push it onto s
spushspop;
return s;
functionL
Note: This function is identical to functionK except the
initial four values are pushed in a different order.
Stack functionL
Stack s;
Stack s;
spush;
spush;
spush;
spush;
while sisEmpty
Pop value from s and push it onto s
spushspop;
return s;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
