Problem 1: Queue Basics
Task 1: Clearing Queue for New Orders
A new restaurant has been added into Nuevo Eats! New orders have been flooding in and the Queue is flooded with orders! The popularity of the different tacos grew fast and the restaurant is overloaded. Look for a way to clear all elements to save the restaurant!
- How can you iterate through the Queue?
- Try to clear the Queue as you go through it!
- Look at the example menu!
// This uses a list as the organizer of the queue.
Queue<String> orders = new PriorityQueue<>();
orders.add("Fish Taco");
orders.add("Beef Taco");
orders.add("Chicken Taco");
orders.add("Fish Taco");
orders.add("Beef Taco");
Task 2: Using Priority Queue to find minimum price
A restaurant is using a Priority Queue to manager orders. The restaurant wants to be able to look at orders based on their prices to better prepare what meals they are making. Specifically, they would like to be able to find the nth minimum price currently in their list. Write a function that looks at their queue of orders and returns the nth minimum price.
- How will you make sure the list is in order?
- What makes it easiest to find the minimum price?
- What if they are looking for the 5th minimum (or lowest) price?