Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

What is the output of the following program? StackPT stk1 = new ArrayStackPT( 8 ); StackPT stk2 = new ArrayStackPT( 8 ); StackPT stk3 =

What is the output of the following program?

StackPT stk1 = new ArrayStackPT( 8 );

StackPT stk2 = new ArrayStackPT( 8 );

StackPT stk3 = new ArrayStackPT( 8 );

StackPT stk4 = new ArrayStackPT( 8 );

QueuePT q1 = new ArrayQueuePT(8);

int n = 22;

while (n > 0){

stk1.push(n%2 + 1);

n = n/2;

}

String result = "";

while (!stk1.isEmpty()){

result += stk1.pop()+ " ";

}

System.out.println("the optput of stk1 : "+result); //___________

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

stk3.push(i);

stk2.push(stk3.pop());

stk2.push(stk3.pop());

stk2.push(stk3.pop());

result = "";

while (!stk2.isEmpty()){

result += stk2.pop()+ " ";

}

System.out.println("the optput of stk2 : "+result); //___________

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

{

if(i%4==0)

stk4.push(i+(int)stk3.pop());

}

result = "";

while (!stk4.isEmpty()){

result += stk4.pop()+ " ";

}

System.out.println("the optput of stk4 : "+result); //___________

int limit = 5;

for(int i = 0; i < limit; i++) {

q1.push((int)Math.pow(i, i));

}

result = "";

while (!q1.isEmpty()){

result += q1.pop()+ " ";

}

System.out.println("the optput of q1 : "+result); //___________

}

}

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

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago