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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!