31 #include <vdk/container.h> 33 inline int parent(
int i) {
return ((i-1) >> 1); }
34 inline int left(
int i) {
return ((i << 1) + 1); }
35 inline int right(
int i) {
return ((i << 1) + 2); }
79 void Heapify(
int i,
int heapsize);
87 for(
int i = 0; i <
size; i++)
88 this->data[i] = source[i];
96 int l = left(i), r = right(i), largest = i;
97 if( (l < heapsize) && (this->data[l] > this->data[i])) largest = l;
98 if( (r < heapsize) && (this->data[r] > this->data[largest])) largest = r;
101 T temp = this->data[i];
102 this->data[i] = this->data[largest];
103 this->data[largest] = temp;
104 Heapify(largest,heapsize);
112 for (
int i = (this->
size()-1)/2 ; i >= 0; i--)
113 Heapify(i,this->
size());
120 int heapsize = this->
size();
124 T temp = this->data[0];
125 this->data[0] = this->data[i];
126 this->data[i] = temp;
provides a base class for generic containers
Definition: container.h:37
void Sort(void)
Definition: vdkheap.h:118
VDKHeap()
Definition: vdkheap.h:63
int size()
Definition: container.h:68
virtual ~VDKHeap()
Definition: vdkheap.h:73
provide a templatized Heap
Definition: vdkheap.h:56