Пример #1
0
 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
 }
Пример #2
0
//DOESNT WORK!!!
void Heap::deleteMin()
{
  swap(0, size-1);
  heap[size-1] = 0;
  size--;
  trickleDown(0);
}
Пример #3
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);
}
Пример #4
0
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";
}
Пример #5
0
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";
}
Пример #6
0
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;
  }
}
Пример #7
0
void Minmax::buildheap(){
	int ind = (size-1)/2;
	for(int i=ind; i>0; i--){
		trickleDown(i);
	}
}