MaxPriorityQueue
This commit is contained in:
57
LinearList/priorityQueue/main.cpp
Normal file
57
LinearList/priorityQueue/main.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
#include <iostream>
|
||||
#include "maxPriorityQueueRealise.h"
|
||||
using namespace std;
|
||||
int main() {
|
||||
maxPriorityQueueRealise<string> q;
|
||||
vector<pair<string, int>> v;
|
||||
v.push_back(make_pair("first", 9));
|
||||
v.push_back(make_pair("second", 8));
|
||||
v.push_back(make_pair("third", 7));
|
||||
v.push_back(make_pair("fourth", 6));
|
||||
v.push_back(make_pair("fifth", 5));
|
||||
v.push_back(make_pair("sixth", 4));
|
||||
v.push_back(make_pair("seventh", 1));
|
||||
v.push_back(make_pair("eighth", 2));
|
||||
v.push_back(make_pair("ninth", 3));
|
||||
q.push(v.at(4));
|
||||
q.push(v.at(3));
|
||||
q.push(v.at(2));
|
||||
q.push(v.at(1));
|
||||
q.push(v.at(0));
|
||||
q.push(v.at(5));
|
||||
q.push(v.at(6));
|
||||
q.push(v.at(7));
|
||||
q.push(v.at(8));
|
||||
cout << q.top() << endl;
|
||||
q.pop();
|
||||
cout << q.top() << endl;
|
||||
q.pop();
|
||||
cout << q.top() << endl;
|
||||
q.pop();
|
||||
cout << q.top() << endl;
|
||||
q.pop();
|
||||
cout << q.top() << endl;
|
||||
q.pop();
|
||||
cout << q.top() << endl;
|
||||
q.pop();
|
||||
cout << q.top() << endl;
|
||||
q.pop();
|
||||
cout << q.top() << endl;
|
||||
q.pop();
|
||||
cout << q.top() << endl;
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
*发现789的三个顺序倒过来了,类的设计正确
|
||||
*本类设计的是maxpriority,如果有重复的priority,优先处理先进入的,也就是FIFO
|
||||
*如果有需求修改可以把比较的时候加入等号,变成FILO
|
||||
first
|
||||
second
|
||||
third
|
||||
fourth
|
||||
fifth
|
||||
sixth
|
||||
ninth
|
||||
eighth
|
||||
seventh
|
||||
*/
|
Reference in New Issue
Block a user