-
Notifications
You must be signed in to change notification settings - Fork 0
/
pqueues.cpp
45 lines (43 loc) · 1.33 KB
/
pqueues.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <string>
#include <queue>
#include "input.h"
using namespace std;
int main(int argc, char const* argv[]) {
priority_queue<string> PQ;
while (true){
string name;
string priority;
string operation;
cout << "What do you want to do? ";
getline(cin, operation);
if (operation.empty()){
break;
}
else if (operation != "add" && operation != "take"){
cout << operation << " isn't a valid operation" << endl;
} else{
if (operation == "take"){
if (!PQ.empty()){
cout << PQ.top() << endl;
PQ.pop();
} else{
cout << "There are no more people in line" << endl;
}
} else if (operation == "add"){
cout << "Name: ";
getline(cin, name);
cout << "Priority: ";
getline(cin, priority);
if (priority.size() < 2){
string combinedString = "0" + priority + " - " + name;
PQ.push(combinedString);
} else{
string combinedString = priority + " - " + name;
PQ.push(combinedString);
}
}
}
}
return 0;
}