Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have two questions that I need help with. 1. After the following statements ex

ID: 3666650 • Letter: I

Question

I have two questions that I need help with.

1.

After the following statements execute, what string is at the top of the stack and what string is at the bottom?

StackInterface<String> stringStack = new OurStack<String>();

stringStack.push("Jim");

stringStack.push("Jess");

stringStack.pop();

stringStack.push("Jill");

stringStack.push("Jane");

stringStack.pop();

2.

Consider the stack that was created in Question 1, and define a new empty stack nameStack.

a. Write a loop that pops the strings from stringStack and pushes them onto nameStack.

b. Describe the contents of the stacks stringStack and nameStack when the loop that you just wrote completes its execution.

Explanation / Answer

1.
Jim is at the Bottom & Jill is at Top

2.

a.
StackInterface<String> nameStack = new OurStack<String>();

while(!stringStack.isEmpty())
{
nameStack.push(stringStack.pop());
}

b.
the stringStacks will contain following elements

Jill
Jim

the nameStacks will contain following elements


Jim

Jill