#pragma once #include #include #include using namespace std; class minHeap { private: vector items; public: minHeap() { } int parent(int i) { return (i - 1) / 2; } //Bubble item at index i //up the heap until //there is no more violation void bubbleUp(int i) { while (items[i] < items[parent(i)]) //there's a violation { swap(items[i], items[parent(i)]); i = parent(i); //update i to be parent. } } void insert(double x) { //Isert item at right-most //bottom leaf position items.push_back(x); bubbleUp(items.size()-1); } void testDisplay() { for (int i = 0; i < items.size(); i++) cout << "Index " << i << ": " << items[i] << endl; } };