Answer on Question #37623 – Programming - C++
#include <iostream>
#include <string>
#include <queue>
#include <sstream>
using namespace std;
int parseNumber(string pStr)
{
stringstream lStream(pStr);
string temp;
int rNumber;
lStream >> temp >> rNumber;
return rNumber;
}
void printQueue(priority_queue<int> pQueue)
{
for(int i = pQueue.size(); i > 0; --i)
{
cout << pQueue.top() << " -";
pQueue.pop();
}
cout << endl;
}
int main()
{
priority_queue<int> lQueue;
string lCommand;
getline(cin, lCommand);
while(lCommand != "quit")
{
if(lCommand[0] == 'a')
lQueue.push(parseNumber(lCommand));
else if(lCommand == "list")
{
printQueue(lQueue);
}
else if(lCommand == "deletemax")
{
lQueue.pop();
}
else
{
cout << "Wrong command" << endl;
}
getline(cin, lCommand);
}
return 0;
}
Comments