Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java Stack please answer the following question 1, 2, 3,4, 5 Q1. What is the value returned by peeking on stack ? Stack stack =

java Stack

please answer the following question 1, 2, 3,4, 5

Q1. What is the value returned by peeking on stack ?

Stack stack = new Stack(20);

for(int i = 0; i < 14; i+=2)

stack.push(i);

stack.pop();

stack.pop();

stack.pop();

stack.peek() =

Q2. What are the values returned by peeking on each stack?

Stack stackOne = new Stack(20);

Stack stackTwo = new Stack(20);

for(int i =0; i<=5; i++)

stackOne.push(i);

stackTwo.push(stackOne.pop());

stackTwo.push(stackOne.pop());

stackTwo.push(stackOne.pop());

stackOne.peek() =

stackTwo.peek() =

Q3. What is printed out?

Stack stack = new Stack(20);

int n = 12;

while (n > 0) {

stack.push(n%2);

n = n/2;

}

int result = "";

while (!stack.isEmpty())

results += stack.pop();

System.out.println(result)

result =

Q4. What elements are in each Stack?

Stack stackOne = new Stack(20);

Stack stackTwo = new Stack(20);

for(int i = 0; i < 7; i++)

stackOne.push(i+2);

for(int i = 0; i < 10; i++)

if(i%4==0)

stackTwo.push(stackOne.peek());

stackOne =

stackTwo =

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

Students also viewed these Databases questions

Question

How does selection differ from recruitment ?

Answered: 1 week ago