#include #include class Event { public: int awesomeness_; int time_; public: Event(int awesomeness, int time) : awesomeness_(awesomeness), time_(time) { } }; struct CompareByTime { static bool compare(const Event& lhs, const Event& rhs) { return lhs.time_ < rhs.time_; } }; struct CompareByAwesomeness { static bool compare(const Event& lhs, const Event& rhs) { return lhs.awesomeness_ < rhs.awesomeness_; } }; template struct CompareFunctor { bool operator()(const Event& x, const Event& y) { return T::compare(x, y); } }; template class PriorityQueue { private: std::list elements; public: void add(const Event& element) { elements.push_back(element); elements.sort(CompareFunctor()); } void print() const { for (std::list::const_iterator Iter = elements.begin(); Iter != elements.end(); Iter++) { std::cout << "( " << Iter->awesomeness_ << ", " << Iter->time_ << " )" << std::endl; } } }; int main() { PriorityQueue p1; PriorityQueue p2; Event e1(3, 4); Event e2(2, 5); p1.add(e1); p2.add(e1); p1.add(e2); p2.add(e2); p1.print(); std::cout << "--------------------------" << std::endl; p2.print(); }