Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this assignment,you will write two implementations of a Priority Queue.For this ADT, removal operations always return the object in the queue of highest priority

For this assignment,you will write two implementations of a Priority Queue.For this ADT, removal operations always return the object in the queue of highest priority that has been in the queue the longest. That is, no object of a given priority is ever removed as long as the queue contains one or more object of a higher priority. Within a given priority FIFO order must be preserved.

Your implementations will be:

1. OrderedArray 2. UnorderedArray

Both implementations must have identical behavior, and must implement the PriorityQueue interface (provided). The implementations must have two constructors, a default constructor with no arguments that uses the DEFAULT_MAX_CAPACITY constant from the PriorityQueue interface, and a constructor that takes a single integer parameter that represents the maximum capacity of the priority queue. The PriorityQueue interface follows:

/* The PriorityQueue ADT may store objects in any order. However, removal of objects from the PQ must follow specific criteria. The object of highest priority that has been in the PQ longest must be the object returned by the remove() method. FIFO return order must be preserved for objects of identical priority.

Ranking of objects by priority is determined by the Comparable interface. All objects inserted into the PQ must implement this interface.

*/ 

--------------------------------

package data_structures;

import java.util.Iterator;

public interface PriorityQueue> extends Iterable {

public static final int DEFAULT_MAX_CAPACITY = 1000;

public boolean insert(E object);

public E remove();

public boolean delete(E obj);

public E peek();

public boolean contains(E obj);

public int Size();

public void clear();

public boolean isEmpty();

public boolean isFull();

public Iterator iterator();

}

-------------------

Additional Details:

Each method must be as efficient as possible. That is, a O(n) is unacceptable if the method could be written with O(log n) complexity. Accordingly, the ordered array implementation must use binary search where possible, such as the contains(), thedelete(E obj)methodandalsotoidentifythecorrectinsertionpointfornew additions.

By convention, a lower number=higher priority. If there are five priorities for a given object, 1 .. 5, then 1 is the highest priority, and 5 the lowest priority.

Your project must consists of only the three files specified (including the provided interface), no additional source code files are permitted. (Do not hand in a copy of PriorityQueue.java, as it is provided to you).

You may not make any modifications to the PriorityQueue interface provided. I will grade your project with my copy of this file.

All source code files must have your name and class account number at the beginning of the file.

All of the above classes must be in a package named 'data_structures'.

You may import java.util.Iterator,

and java.util.NoSuchElementException only. If you feel that you need to import anything else, let me know. You are expected to write all of the code yourself, and you may not use the Java API for any containers.

Your code must not print anything.

Your code should never crash, but must handle any/all error conditions gracefully.

i.e. if the user attempts to call the clear() method on an empty PQ, or remove an item from an empty PQ, the program should not crash. Be sure to follow the specifications for all methods.

You must write generic code according to the interface provided. You may not add any public methods to the implementations, but you may add private ones, if needed.

Your code may generate unchecked cast warnings when compiled, but it must compile and run correctly on edoras to receive any credit.

Tester/driver programs will be provided going forward to help you test your code.

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

Handbook Of Relational Database Design

Authors: Candace C. Fleming, Barbara Von Halle

1st Edition

0201114348, 978-0201114348

More Books

Students also viewed these Databases questions

Question

Is there a competitiveness problem in the United States?

Answered: 1 week ago

Question

What are the first signs that a person might be depressed?

Answered: 1 week ago

Question

Identify how culture affects appropriate leadership behavior

Answered: 1 week ago