#include #include #include #include "compact_queue.h" using namespace std; class animal_count { string animal; unsigned int count = 0; public: animal_count(string a, unsigned int c) : animal(a), count(c) {} animal_count() {} string to_string(){ char cstr[12]; // Some C++ programmers don't like to import old C methods sprintf(cstr, "%d", count); return animal + " " + cstr; } bool operator>(const animal_count& b){ return count > b.count; } // friend bool operator>(const animal_count& a, const animal_count& b); }; int main(){ animal_count squirrels("squirrel", 17); animal_count cats("cat", 5); animal_count chickens("chicken", 91); compact_queue test_queue(10); test_queue.enqueue(squirrels); test_queue.enqueue(cats); test_queue.enqueue(chickens); test_queue.sort(); while(!test_queue.empty()) cout << test_queue.dequeue().to_string() << endl; }