Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Queues, Deques and Priority Queues. Enter the necessary code where indicated (using: MyQues.java - below and questions) How would you use a stack to verify

Queues, Deques and Priority Queues.

Enter the necessary code where indicated (using: MyQues.java - below and questions)

How would you use a stack to verify whether a given string is a palindrome or not?

How would you check if a string is a palindrome or not, using queues and deques?

import java.util.*;

/*

* From useQueue, print out

* [Strawberries, Whipped Cream, Blueberries, Whipped Cream,

Strawberries, Whipped Crean, Powdered Choclolate]

*

* From useDeque, print out

* [Pineapple Cake, Whipped Cream, Strawberries, Whipped Cream, Powdered

Choclolate]

*

* From usePque, print out

* [Bananas, Vanilla Wafers, Whipped Cream]

*

* Do not remove or modify the code below.

* You can add code where indicated.

*/

public class MyQues{

public static void main(String[] args){

System.out.println();

useQueue();

System.out.println();

useDeque();

System.out.println();

usePque();

System.out.println();

}

public static void useQueue(){

Queue myQueue = new LinkedList<>();

myQueue.offer("Blueberries");

myQueue.offer("Strawberries");

myQueue.offer("Whipped Cream");

myQueue.poll();

myQueue.poll();

myQueue.offer("Whipped Cream");

myQueue.offer("Strawberries");

myQueue.offer("Whipped Cream");

myQueue.offer("Powdered Choclolate");

// Add code below

// Add code above

System.out.print(myQueue);

}

public static void useDeque(){

Deque myQueue = new LinkedList<>();

myQueue.offer("Blueberries");

myQueue.offer("Strawberries");

myQueue.offer("Whipped Cream");

myQueue.poll();

myQueue.poll();

myQueue.offer("Whipped Cream");

myQueue.offer("Strawberries");

myQueue.offer("Whipped Cream");

myQueue.offer("Powdered Choclolate");

// Add code below

// Add code above

System.out.print(myQueue);

}

public static void usePque(){

PriorityQueue myQueue = new PriorityQueue<>();

myQueue.offer("Blueberries");

myQueue.offer("Strawberries");

myQueue.offer("Whipped Cream");

myQueue.poll();

myQueue.poll();

myQueue.offer("Whipped Cream");

myQueue.offer("Strawberries");

myQueue.offer("Whipped Cream");

myQueue.offer("Powdered Choclolate");

// Add code below

// Add code above

System.out.print(myQueue);

}

}

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

Medical Image Databases

Authors: Stephen T.C. Wong

1st Edition

1461375398, 978-1461375395

More Books

Students also viewed these Databases questions