(Solved):Java Question: Show the contents of two initially empty stacks after each of the following statements execute. Assume x, y, m, and q are objects. If you are writing the contents of your stack horiz… View Answer…

 

Question

Java Question :

Show the contents of two initially empty stacks after each of the following statements execute. Assume x, y, m, and q are objects.

If you are writing the contents of your stack horizontally, use the left as the bottom and right as the top of your stack.

stack1.push(x)

stack1.push(y )

stack2.push(m)

stack2.push(q)

stack1.push(stack2.peek())

stack2.push(stack1.pop())

stack1.push(stack1.peek())

stack2.pop()

 

EXPERT ANSWER

stack1.push(x)
1: BOTTOM [ x ] TOP
2: BOTTOM [ ] TOP
stack1.push(y )
1: BOTTOM [ x y ] TOP
2:

Scroll to top