Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following stack: + - - - - + | 1 6 | < - top + - - - - + | 2

Consider the following stack:
+----+
|16|<- top
+----+
|20|
+----+
|12|
+----+
|19|<- 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;
s.push(16);
s.push(20);
s.push(12);
s.push(19);
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;
s.push(19);
s.push(12);
s.push(20);
s.push(16);
return s;
}
functionC()
Stack functionC()
{
Stack s;
s.push(16);
s.push(20);
s.push(12);
s.push(19);
s.peek();
s.peek();
s.peek();
s.peek();
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;
s.push(19);
s.push(12);
s.push(20);
s.push(16);
s.peek();
s.peek();
s.peek();
s.peek();
return s;
}
functionE()
Stack functionE()
{
Stack s;
s.push(16);
s.push(20);
s.push(12);
s.push(19);
s.pop();
s.pop();
s.pop();
s.pop();
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;
s.push(19);
s.push(12);
s.push(20);
s.push(16);
s.pop();
s.pop();
s.pop();
s.pop();
return s;
}
functionG()
Stack functionG()
{
Stack s;
s.push(16);
s.push(20);
s.push(12);
s.push(19);
// The return value from s.peek() is pushed onto s.
s.push(s.peek());
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;
s.push(19);
s.push(12);
s.push(20);
s.push(16);
// The return value from s.peek() is pushed onto s.
s.push(s.peek());
return s;
}
functionI()
Stack functionI()
{
Stack s;
s.push(16);
s.push(20);
s.push(12);
s.push(19);
// The return value from s.pop() is pushed onto s.
s.push(s.pop());
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;
s.push(19);
s.push(12);
s.push(20);
s.push(16);
// The return value from s.pop() is pushed onto s.
s.push(s.pop());
return s;
}
functionK()
Stack functionK()
{
Stack s1;
Stack s2;
s1.push(16);
s1.push(20);
s1.push(12);
s1.push(19);
while (!s1.isEmpty())
{
// Pop value from s1 and push it onto s2.
s2.push(s1.pop());
}
return s2;
}
functionL()
// Note: This function is identical to functionK(), except the
// initial four values are pushed in a different order.
Stack functionL()
{
Stack s1;
Stack s2;
s1.push(19);
s1.push(12);
s1.push(20);
s1.push(16);
while (!s1.isEmpty())
{
// Pop value from s1 and push it onto s2.
s2.push(s1.pop());
}
return s2;
}

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2014 Nancy France September 15 19 2014 Proceedings Part 2 Lnai 8725

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448505, 978-3662448502

More Books

Students also viewed these Databases questions

Question

What will you do or say to Anthony about this issue?

Answered: 1 week ago