Create a PriorityQueue class and implement a new enqueue() method to implement a priority queuing
discipline. For efficiency, priority queues are often implemented using a heap, so that both insertion and removal
of items can be done in O(log n) time. However, we are going to use a simple naive method and simply insert
new items into a link list that we keep sorted by priority. Doing this means that the insertion (enqueue())
operation becomes O(n), but since for a priority queue we always want the next item with the highest priority
for a dequeue(), dequeue() is still O(1) constant time, since we will keep items ordered by priority and the
highest priority item in the queue should always be at the front of the list.
This may sound like a lot, but there is really not too much to do to get a basic priority queue working. You
need to perform the following steps
1. Create a new class called PriorityQueue that inherits (using public inheritance) and derives from the
LQueue class. This class still needs to be a template class, as it needs to be able to handle queues of
different types of objects. I have set the member variables of the LQueue class to be protected, which
means that your PriorityQueue class methods will be able to access and refer to the queueFront and
queueBack member variables. You should insert your class definition for your PriorityQueue at the end
of the “Queue.hpp” file.
The only method you need to implement/override is the enqueue() method. All other methods should work
correctly using the LQueue() implementations you will inherit. But since you are overriding enqueue()
you do need to put a new declaration for this function in your PriorityQueue class declaration, but this
will be the only function or variable (re)defined in the PriorityQueue.
2. Once you have the declaration working, you will need to create your implementation of the enqueue()
method for the PriorityQueue. As we already mentioned, instead of always just inserting the new
item/node at the back of the queue, you instead need to do some some extra work and insert the new node
into the linked list at the proper position so that the linked list is ordered by priority. You can assume that
the objects inserted into a PriorityQueue are overloaded so that boolean comparisons (like operator<,
operator<=, operator>, etc.) are defined to order object by their priority. The Job class that you will be
managing with your PriorityQueue has had these operators defined to order jobs by their priority level.
The pseudo-code for the algorithm your enqueue() function needs to perform
Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.Read more
Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.Read more
Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.Read more
Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.Read more
By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.Read more