Question: Solve all the questions with proper answer 1. Which item is the second item to be removed from the queue, when the operations below are

Solve all the questions with proper answer

1.

Which item is the second item to be removed from the queue, when the operations below are performed, in the order listed, on an empty queue?

queue.enqueue("Ryan") queue.dequeue( ) queue.enqueue("Banks") queue.enqueue("Private") queue.enqueue("Hanks") queue.dequeue( ) queue.dequeue( ) queue.enqueue("Mr.") queue.enqueue("Saving") queue.enqueue("Forrest") queue.enqueue("Gump") queue.dequeue( ) queue.dequeue( ) queue.dequeue( )

2.

Select which applications listed below typically make use of stacks. Check all that apply.

Evaluating postfix arithmethic expressions
Keeping track of a program's active modules/methods
Operating system task scheduling
Depth-first search (DFS) graph traversal; backtracking, in general

3.

The code below pushes three random integer values onto intStack and goes on to move those three values into intQ. When this code segment is done executing, what is the order, from front to rear, of the three values in intQ?

ArrayStack intStack = new ArrayStack(); ArrayQueue intQ = new ArrayQueue(); intStack.push(randomValue1); intStack.push(randomValue2); intStack.push(randomValue3); intQ.enqueue(intStack.pop()); int x = intStack.pop(); if (x <= intStack.peek()) { intQ.enqueue(x); x = intStack.pop(); intQ.enqueue(x); } else { intQ.enqueue(intStack.pop()); intQ.enqueue(x); } intStack.push(intQ.dequeue()); if (intStack.peek() >= x) { intQ.enqueue(intStack.pop()); } else { x = intStack.pop(); intStack.push(intQ.dequeue()); if (x <= intStack.peek()) { intQ.enqueue(x); intQ.enqueue(intStack.pop()); } else { intQ.enqueue(intStack.pop()); intQ.enqueue(x); } intQ.enqueue(intQ.dequeue()); }

front to rear: least - greatest - middle
front to rear: middle - greatest - least
front to rear: least - middle - greatest
front to rear: greatest - middle - least

4,

Given a queue populated with an unknown number of elements, along with an empty stack object, develop an algorithm in Java-like pseudocode that removes all of the items from the queue and puts them back in the queue in reverse of their original order.

The only stack and queue operations available to you are the ones specified in StackInterface.java and QueueInterface.java, the interfaces provided for Programming Project #2, that we also used for class exercises.

Please use myQ as the name of the queue, and myStack for the name of the stack.

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!