Heap and Queueing Assignment using visual studio. C++
#pragma once #include <math.h> #include <iostream> using namespace std; #ifndef HEAPHPP #define HEAPHPP template <class T> void Heap<T>::_bubbleUp(int index) { } template <class T> void Heap<T>::_bubbleDown(int index) { } template <class T> void Heap<T>::insert(T item) { } template <class T> T Heap<T>::extractMax() { return T(); } template <class T> void Heap<T>::printHeapArray() { for (int i = 0; i < _n; i++) cout << _heap[i] << " "; cout << endl; } template <class T> int Heap<T>::_lookFor(T x){ // not a very good implementation, but just use this for now. int i; for(i=0;i<_n;i++) if (_heap[i] == x) return i; return -1; } template <class T> void Heap<T>::decreaseKey(T from, T to) { } template <class T> void Heap<T>::increaseKey(T from, T to) { } template <class T> void Heap<T>::deleteItem(T x) { } template <class T> void Heap<T>::printTree() { int parity = 0; if (_n == 0) return; int space = pow(2,1 + (int) log2f(_n)),i; int nLevel = (int) log2f(_n)+1; int index = 0,endIndex; int tempIndex; for (int l = 0; l < nLevel; l++) { index = 1; parity = 0; for (i = 0; i < l; i++) index *= 2; endIndex = index * 2 - 1; index--; tempIndex = index; while (index < _n && index < endIndex) { for (i = 0; i < space-1; i++) cout << " "; if(index==0) cout << "|"; else if (parity) cout << "\\"; else cout << "/"; parity = !parity; for (i = 0; i < space; i++) cout << " "; index++; } cout << endl; index=tempIndex; while (index < _n && index < endIndex) { for (i = 0; i < (space-1-((int) log10(_heap[index]))); i++) cout << " "; cout << _heap[index]; for (i = 0; i < space; i++) cout << " "; index++; } cout << endl; space /= 2; } } #endif