#pragma once #include #include using namespace std; class minHeap { private: vector items; //return index of parent of index i int parent(int i) { return (i - 1) / 2; } //bubble up item at index location //unitl no more violation void bubbleUp(int index) { int i = index; while (items[i] < items[parent(i)]) //there is a parent viloation at i) { swap(items[i], items[parent(i)]); i = parent(i); } } public: minHeap() { } void insert(double x) { //add x to bottom-rightmost of tree items.push_back(x); //buble item up heap until no more violation bubbleUp(items.size()-1); } void testDisplay() { for (int i = 0; i < items.size(); i++) cout << "Index " << i << ": " << items[i] << endl; } };