#include "heap.h" #include using namespace std; float random_float(){ return rand() % 1000000 / 1000.0 ; } size_t allocation_count = 0; class heapstring { char *contents; size_t length; public: heapstring(const char* s){ length = strlen(s); contents = new char[length + 1]; allocation_count++; strcpy(contents, s); } heapstring(const heapstring& o){ length = o.length; contents = new char[length + 1]; allocation_count++; strcpy(contents, o.contents); } bool operator>(const heapstring& o){ return strcmp(contents, o.contents) > 0; } ~heapstring(){ delete [] contents; } friend ostream& operator<<(ostream& out, const heapstring& toprint){ return out << toprint.contents; } }; int main(){ /* binary_heap float_heap; for(int i = 0; i < 50; i++) float_heap.insert(random_float()); float_heap.remove(319.58); while(!float_heap.empty()) cout << float_heap.pop() << endl; */ binary_heap hos; // hos = heap of strings hos.insert(heapstring("monkey")); hos.insert(heapstring("goose")); hos.insert(heapstring("moose")); // while(!hos.empty()) // cout << hos.pop() << endl; cout << "Final allocation count (from within heapstring): " << allocation_count << endl; return 0; }