#pragma once #include using namespace std; class heap { private: vector items; int parent(int i) { return (i - 1) / 2; } public: heap() {} //Item at index i is sus. //It might be smaller than it's parent //Bubble it up the heap until there's //no more violation void bubbleUp(int i) { while(items[i] < items[parent(i)]) { swap(items[i], items[parent(i)]); i = parent(i); } } void insert(double x) { //add item at back of array/ //bottom-most right-most leaf items.push_back(x); bubbleUp(items.size() - 1); } void testDisplay() { for (int i = 0; i < items.size(); i++) { cout << i << ": " << items[i] << endl; } } };