Question: The priority_queue class can be used to store elements of a certain type (int, string, etc.) and then retrieve them in decreasing order. You can

 The priority_queue class can be used to store elements of a

The priority_queue class can be used to store elements of a certain type (int, string, etc.) and then retrieve them in decreasing order. You can declare a priority_queue of integers like this: priority_queue pq; You can perform the following operations on a priority_queue of integers: void push (int value);//inserts a new integer in to the priority queue int top ();//returns the current biggest int in the queue void pop ();//removes the current biggest int from the queue int size ();//returns the number of ints in the queue Using this knowledge, write a C++ program to do the following: Read a list of numbers from a file, called file.txt, which has one number per line. You should use an if stream and either the extraction operator (> >) or the get line method. Put these numbers into a priority. queue. Print the numbers to the screen in descending order. You should divide your program into these functions: void read Numbers (cost string& filename, priority_queue & pq) This function takes a filename by cost reference and a priority queue by reference. It should open filename using an if stream and read the numbers into pq. void print Numbers (priority_queue & pq) This function should repeatedly print and then remove the biggest thing in p

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!