Question
Given the following sequence of stack operations, what is the top item on the stack when the sequence is complete? Stack s = new Stack();
Given the following sequence of stack operations, what is the top item on the stack when the sequence is complete?
Stack s = new Stack();
s.push("x");
s.push("y");
s.pop();
s.push("z");
s.peek();
x
y
z
The stack is empty
2. Given the following sequence of stack operations, what is the top item on the stack when the sequence is complete?
Stack s = new Stack();
s.push(81);
s.push(64);
s.push(49)
while (! s.isEmpty()){
s.pop();
}
s.pop()
An error will occur.
81
49
64
3. Suppose you have the following series of queue operations. What items are left on the queue?
Queue q = new Queue();
q.enqueue("dog");
q.enqueue("cat");
q.enqueue("bird");
q.dequeue();
dog, cat, bird
dog, bird
dog, cat
cat, bird
4.
Suppose you have the following series of deque operations. What will be the deque contents?
Deque deq = new Deque();
deq.push-front(97);
deq.push-back(71);
deq.pop-front();
deq.push-front(45);
deq.push-back(68);
68, 97, 45
45, 97, 71
45, 68, 71
45, 71, 68
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started