Binary Heap in C++
Implementation Binary heap data structure in C++. This class implemeted for MAX HEAP data structure. Github: sourcecode/binaryheap.h #include <iostream> #include <vector> using namespace std; /* class binary heap (priority queue) */ /* This class implemented for MAX_HEAP */ template <typename T> class binaryheap { private: int heaptype; //Max heap or min heap. This class implemented for MAX_HEAP vector<T> heap; //heap datastructure public: //constructor binaryheap(int type) :heaptype(type) {} //parameterised constructor binaryheap(T *arr, int _size) { if (_size != 0) { for (int i=0; i<_size;i++) { //push all the elements to the vector heap.push_back(arr[i]); } } //heapify for (int i = (_size / 2) - 1; i >= 0; i--) { sink(i); } } //add the element void add(T elem) { int m_size = (int)heap.size(); //add element at the back heap.push_back(elem); if (m_size != 0) { //hea...