Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

9th Edition

B01JXPZ7AK, 9780805360479

More Books

Students also viewed these Databases questions