Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started