0

I am trying to implement priority queue using heap in c++.The code given below is working fine.But i want to generate a file containing priority (integer)and value(char or string)associated to it. Now use this file as input it to the code below to generate a sequence of values in increasing order of priorities.

#include<queue>
#include <utility>

int main() 
{

    std::priority_queue<std::pair<int, std::string> > pq;
    pq.push(std::make_pair(3, "Clear drains"));
    pq.push(std::make_pair(4, "Feed cat"));
    pq.push(std::make_pair(5, "Make tea"));
    pq.push(std::make_pair(1, "Solve RC tasks"));
    pq.push(std::make_pair(2, "Tax return"));
    while (!pq.empty())
    {
        std::cout << pq.top().first << ", " << pq.top().second << std::endl;
        pq.pop();
    }
    return 0;

}
user123
  • 1
  • 2
  • do you want to save contents of a priority_queue into a file in an increasing order? – sithereal Mar 02 '15 at 20:17
  • input file will contain (value, priority) pairs each separated by a newline. and the output is, values in increasing order of their priority – user123 Mar 02 '15 at 20:51
  • what did you try so far for reading input from a file? – sithereal Mar 02 '15 at 20:56
  • possible duplicate of [How to read-write into/from text file with comma separated values](http://stackoverflow.com/questions/1474790/how-to-read-write-into-from-text-file-with-comma-separated-values) – aruisdante Mar 02 '15 at 20:57
  • You aren't 'implementing' a PQ, you are *using* one, and a PQ *is* a heap. – user207421 Mar 02 '15 at 21:10
  • thats right @EJP .and that what is causing me the problem(The ADT nature). i am just not able to figure out how to use getline() or readFile() functions here. – user123 Mar 02 '15 at 21:53

0 Answers0