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.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.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.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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started