//The below code assumes that you have overloaded the output ostream. If this is a problem // and you prefer to provide a print method for the binary heap, there is commented out code // that you can use to replace the lines just above them. #include #include "BinaryHeap.h" using namespace std; int main(){ BinaryHeap h(10); Tracker** trackers = new Tracker*[10]; cout << "The isEmpty method returns " << h.isEmpty() << endl; trackers[0] = h.put(5.25,"a"); trackers[1] = h.put(3.5,"b"); trackers[2] = h.put(4.5,"c"); cout << "After inserting 5.25 (data a), 3.5 (data b), 4.5 (data c), the heap is:" << endl; cout << h << endl; //h.print(); trackers[3] = h.put(3.14,"d"); cout << "After inserting 3.14 (data d), the heap is:" << endl; cout << h << endl; //h.print(); trackers[4] = h.put(7.3,"e"); trackers[5] = h.put(20.0,"f"); trackers[6] = h.put(4.75,"g"); cout << "After inserting 7.3 (data e), 20.0 (data f), 4.75 (data g), the heap is:" << endl; cout << h << endl; //h.print(); trackers[7] = h.put(1.5,"h"); cout << "After inserting 1.5 (data h), the heap is:" << endl; cout << h << endl; //h.print(); trackers[8] = h.put(8.8,"i"); trackers[9] = h.put(9.0,"j"); cout << "After inserting 8.8 (data i), 9.0 (data j), the heap is:" << endl; cout << h << endl; //h.print(); cout << "There are " << h.size() << " elements in the heap." << endl; cout << "The isEmpty method returns " << h.isEmpty() << "." << endl << endl; cout << "decreasing key for trackers[0] (which is node with key 5.25) to 1.0" << endl; if (trackers[0]->decreaseKey(1.0)) cout << "The key was decreased" << endl; else cout << "The key was not decreased" << endl; cout << "The heap is:" << endl; cout << h << endl; //h.print(); cout << "decreasing key for trackers[2] (which is node with key 4.5) to 1.25" << endl; if (trackers[2]->decreaseKey(1.25)) cout << "The key was decreased" << endl; else cout << "The key was not decreased" << endl; cout << "The heap is:" << endl; cout << h << endl; //h.print(); cout << "decreasing key for trackers[3] (which is node with key 3.14) to 5.15" << endl; if (trackers[3]->decreaseKey(5.15)) cout << "The key was decreased" << endl; else cout << "The key was not decreased" << endl; for (int i=0; i < 4; i++){ cout << "Removing the key " << h.minimumKey() << endl; cout << " it had data " << h.extractMin() << endl; for (int j=0; j < 4; j++) cout << " trackers[" << j << "]->inHeap() returns " << trackers[j]->inHeap() << endl; cout << "The heap is:" << endl; cout << h << endl; //h.print(); } cout << "There are " << h.size() << " elements in the heap." << endl; return 1; }