Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

20. Show what is written by the following segments of code, given that item1, item2, and item3 are int variables, and s is an object

20. Show what is written by the following segments of code, given that item1, item2, and item3 are int variables, and s is an object that its the abstract description of a stack as given in the section. Assume that you can store and retrieve variables of type int on s.

a.

item1 = 1; item2 = 0; item3 = 4;

s.push(item2); s.push(item1); s.push(item1 + item3);

item2 = s.top();

s.push (item3*item3); s.push(item2); s.push(3);

item1 = s.top();

s.pop();

System.out.println(item1 + " " + item2 + " " + item3);

while (!s.isEmpty())

{

item1 = s.top(); s.pop();

System.out.println(item1);

}

b.

item1 = 4; item3 = 0; item2 = item1 + 1;

s.push(item2); s.push(item2 + 1); s.push(item1);

item2 = s.top(); s.pop();

item1 = item2 + 1;

s.push(item1); s.push(item3);

while (!s.isEmpty())

{

item3 = s.top(); s.pop();

System.out.println(item3);

}

System.out.println(item1 + " " + item2 + " " + item3);

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

Main Memory Database Systems

Authors: Frans Faerber, Alfons Kemper, Per-Åke Alfons

1st Edition

1680833243, 978-1680833249

More Books

Students also viewed these Databases questions

Question

What Is acidity?

Answered: 1 week ago

Question

Explain the principles of delegation

Answered: 1 week ago

Question

State the importance of motivation

Answered: 1 week ago

Question

Discuss the various steps involved in the process of planning

Answered: 1 week ago

Question

What are the challenges associated with tunneling in urban areas?

Answered: 1 week ago

Question

Question What is a Roth 403 (b) plan?

Answered: 1 week ago

Question

Question Can a Keogh plan fund be reached by the owners creditors?

Answered: 1 week ago