Question: 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

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!