Current location - Health Preservation Learning Network - Healthy weight loss - C++ language maxheap.h header file
C++ language maxheap.h header file
# define DefaultSize 10;

Template & ltT class, e class & gt

Structural element {

T bond;

Other data of the field;

Element & ltt, E>& ampoperator =(Element & lt; t,E & gt& ampx)

{ key = x.keyoperator = x.otherdata}

Boolean operator > = (element <; T, E>& ampx){return key>= x.key}

Boolean operator & lt(Element & ltt, E>& ampx){return key & ltx.key}

};

Template & ltT class, e class & gt

Maximum heap of categories {

Public:

max heap(int SZ = DefaultSize);

max heap(Element & lt; t,E & gtarr[],int n);

~ max heap(){ delete[]heap; }

Int Insert(const element & ltt, e> & ampx);

int Remove(Element & lt; t,E & gt& ampx);

bool IsEmpty()const { return currentSize = = 0; }

bool is full()const { return currentSIze = = MaxHeapSize; }

Private:

Element & ltt, E>* heap;

int currentSize

int MaxHeapSize

void siftDown(int start,int m);

void sift up(int start);

Swap(const int i,const int j)

{ Element & ltt,E & gttmp = heap[I]; heap[I]= heap[j]; heap[j]= tmp; }

};

Template & ltT class, e class & gt

void MaxHeap & ltt,E & gt* sift down(const int start,const int m{

int i = startint j = 2 * I+ 1;

Element & ltt, e> temp = heap [I];

And (I < = m) {

if(j & lt; m & amp& ampheap[j]& lt; heap[j+ 1])j++;

if(temp & gt; = heap[j])break;

Otherwise {

heap[I]= heap[j];

I = j; j = 2 * j+ 1;

}

}

heap[I]= temp;

};