Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!