Skip to content

Instantly share code, notes, and snippets.

@ygabo
Created August 20, 2013 18:06
Show Gist options
  • Save ygabo/6284984 to your computer and use it in GitHub Desktop.
Save ygabo/6284984 to your computer and use it in GitHub Desktop.
Priority queue with a custom class.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <fstream>
#include < ctime >
#include <algorithm>
#include <numeric>
#include <set>
#include <queue>
using namespace std;
class Person{
public:
int num;
Person():num(0){}
Person(int i):num(i){}
};
bool operator<(const Person &a, const Person &b){
return a.num > b.num;
}
int main(){
Person a(1),b(2),c(3),e(4);
priority_queue<Person> d;
d.push(b); d.push(c); d.push(e); d.push(a);
cout << d.size() << endl;
queue<Person> s();
while(!d.empty()){
cout << d.top().num << " ";
d.pop();
}
cout << endl <<"done" <<endl;
cin.get();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment