Question: Description : For this programming assignment, you will implement a Priority Queue in C++. Your Priority Queue can grow dynamically as in the Stack assignment

Description:

For this programming assignment, you will implement a Priority Queue in C++. Your Priority Queue can grow dynamically as in the Stack assignment (although you should use a method with amortized cost O(1) for insertion) or you may make a Priority Queue large enough to fit all of your data ahead of time. You will build three different implementations of the Priority Queue. Two of these implementations will be based on a List. The first list implementation, UnsortedPQ, should use an unsorted list to store the data. The second list implementation, SortedPQ, should use a sorted list. The third implementation, HeapPQ, should be an array-based implementation of a Heap.

We will test your implementations using a set of numbers in a text file named numbers.txt. Each line of the file will contain a number. The first number will be which Priority Queue to use (0=UnsortedPQ, 1=SortedPQ, 2=HeapPQ). The second number will be the number of remaining elements in the file, n. The first two numbers of the file (queue type and n) will NOT be inserted into your Priority Queue. However, the remaining n numbers will be inserted. You should then remove all n numbers and print them to the screen. For an example numbers.txt file.

Using your three implementations, you will also time how long it takes to insert n random numbers and the total time to insert n random numbers and remove n random numbers. You may use a random number generating as opposed to the file input above. You can time how long insertion takes using the StopWatch class provided on previous PAs. You should measure the total time at fixed intervals. You will then show a graph of the total insertion time versus the number of items inserted for each implementation. You will then time how long insertion and removal takes by inserting n numbers and removing n numbers for each implementation. You will then graph the sorting time versus the number of elements. This process will allow you to see how your choice of implementation can affect performance.

BONUS (10 Points):

Implement a bottom up construction for the heap.

Coding Portion (50 Points):

Start with the following template: PriorityQueue.h, and create three versions of the Priority Queue (using templates for the type of object) filling in all of the member functions.

Be sure to test the correctness of your algorithms and implementations (we will).

Your code will be graded based on whether or not it compiles, runs, produces the expected output, produces correct output, whether or not your experimental setup is correct, and your coding style (does the code follow proper indentation/style and comments).

//numbers.txt

1 10 7 23 9 3 12 5 2 32 6 42

//priorityQueue.h

#ifndef PRIORITY_QUEUE_H #define PRIORITY_QUEUE_H #include  using namespace std; /** * Note: in order to try to make things easier, the queue below will only have a single type of value * in it instead of a (key, value) pair. You could still store a (key, value) pair, but you would * make a priority queue that stored an object with both the key/value in it and a comparison operator * that only compared the keys. */ template  class PriorityQueue { private: // data here public: PriorityQueue(void); // Performs an insertion of "n" items from dataArray into the priority queue // BONUS: perform a bottomup heap construction for the heap. Compare the time it takes to perform a // bottom up construction to inserting n items in your experimental section of your report. PriorityQueue ( Type *dataArray, int n ); ~PriorityQueue(void); bool empty(void); int size(void); // inserts a piece of data into the priority queue void insert ( Type data ); // removes and returns the minimum value in the queue // you must handle the error if the queue is empty Type removeMin ( void ); // return the minimum value in the queue without removing it // you must handle the error if the queue is empty Type minValue ( void ); }; #endif

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!