Asig Stacks
Asig Stacks
1. If you push the objects x, y, and z onto an initially empty stack, in what order will three
consecutive pop operations remove them from the stack?
The stacks would look like: Z, Y, and X.
2. What pseudocode statements create a stack of the three strings “Carlos”, “Darius”, and
“Sophia”, in that order with “Carlos” at the top?
myStack.push(“Sophia”);
myStack.push(“Darius”);
myStack.push(“Carlos”);
3. Suppose that s and t are empty stacks and a, b, c, and d are objects. What do the stacks contain
after the following sequence of operation executes?
s.push(a); S: a T:
s.push(b); S: a b T:
s.push(c); S: a b c T:
t.push(d); S: a b c T: d
t.push(s.pop()); S: a b T: d c
t.push(s.peek()); S: a b T: d c b
s.push(t.pop()); S: a b b T: d c
t.pop(); S: a b b T: d
4. What are the contents of the stack pile after the following statements execute? Assume that
MyStack is a class that implements the interface StackInterface.
Pile.push(“Jazmin”);
Pile.push(“Jess”);
Pile.push(“Jack”);
Pile.push(pile.pop()):
Pile.push(pile.peek());
Pile.push(“Seiji”);
String name = pile.pop();
Pile.push(pile.peek());