


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Class: DATA STR ALG GEN PRO; Subject: COMPUTER PROGRAMMING; University: Florida State University; Term: Fall 2006;
Typology: Assignments
1 / 4
This page cannot be seen from the preview
Don't miss anything!



In this assignment, you will be required to implement a template class for a priority queue object, i.e. you are required to complete the implementation for the Priority_Queue class. You will also be required to implement the heap sort algorithm on the priority queue to rearrange the items of a container in descending order.
A partial interface and implementation of the Priority_Queue class is provided in the distributed priority_queue.h files. The underlying Priority_Queue data structure is any container type that has its operator [] overloaded. A Priority_Queue object could be declared as , Priority_Queue <vector
void PushHeap(const value_type& value) { c.push_back(value); RestoreHeap(c.size()-1); } void PopHeap() { swap(c[0], c[c.size()-1]); c.pop_back(); RestoreHeap(0); } protected: C c; P Compare; }; The full implementation of the priority_queue.h file MUST contain at least the following declarations: Priority_Queue(): Constructor for the Priority_Queue object. Priority_Queue(const C& container): Constructor for the Priority_Queue object that initializes the container type c to container. In addition, this method should also call the MakeHeap method to ensure that c adheres to its heap property. void Push(const value_type& value): Adds item of type value to priority queue. This method should call the PushHeap method to add item to the underlying container and maintain its heap property. void Pop(): Removes the item from the top of the priority queue. This method should call the PopHeap method to remove the item from the underlying container and maintain its heap property. unsigned int Size(): Returns the size of the priority queue. bool Empty(): Returns true if the priority queue is empty and false otherwise. value_type& Top(): Returns the element located at the top of the priority queue. void Display(std::ostream&, char ofc = '\0') const: Displays all the elements in the priority queue. void MakeHeap(): Rearranges the elements within the container c, in-place so as to maintain the heap property of the priority queue. Must have cost at most O(N). In particular, using generic sorting algorithms such as quicksort, which has cost O(N log N), will be marked down for inefficiency.