void freqtable::pop() { delete table.front(); // delete the actual element table.front() = table.back(); // overwrite first with last address table.pop_back(); trickleDown(0); // trickle last address to new its place }
//DOESNT WORK!!! void Heap::deleteMin() { swap(0, size-1); heap[size-1] = 0; size--; trickleDown(0); }
//need to modify deletemax and min - THESE DO NOT WORK!!! void Heap::deleteMax() { int max = findMax(0); swap(max, (size-1)); heap[size-1] = 0; size--; trickleDown(max); }
void Minmax::deleteMin(){ int tmp= heap[1]; heap[1]=heap[size-1]; heap[size-1]=tmp; size--; trickleDown(1); //std::cout << tmp << "has been deleted.\n\n"; }
void Minmax::deleteMax(){ int tmp; //find larger of the two second level values if(heap[2]>heap[3]){ tmp=heap[2]; heap[2]=heap[size-1]; heap[size-1]=tmp; size--; trickleDown(2); } else{ tmp=heap[3]; //place last value of the heap in place of the max value, trickle it down heap[3] = heap[size-1]; heap[size-1]=tmp; size--; trickleDown(3); } std::cout<< tmp << " has been deleted.\n\n"; }
void Heap::heapify() { std::cout<<"original heap:"<<std::endl; levelOrder(); int index = size-1; for(int i = int(floor((index-1)/2)); i>=0; i--) { std::cout<<"i = "<<i<<std::endl; trickleDown(i); levelOrder(); std::cout<<"\n"<<std::endl; } }
void Minmax::buildheap(){ int ind = (size-1)/2; for(int i=ind; i>0; i--){ trickleDown(i); } }