17 #ifndef HEAP_TREE_TYPE_H_ 18 #define HEAP_TREE_TYPE_H_ 66 template<
class HT_TYPE>
78 findChildren(index, childL, childR);
79 unsigned int indexL, indexR;
80 indexL=findIndex(childL); indexR=findIndex(childR);
81 int useIndexL=0, useIndexR=0;
83 if (indexL<unsortedCount)
84 if ((*
this)[index]<(*
this)[indexL])
86 if (indexR<unsortedCount)
87 if ((*
this)[index]<(*
this)[indexR])
89 if (useIndexR && useIndexL)
90 if ((*
this)[indexL]<(*
this)[indexR])
100 swapIfBigger(indexR);
110 void swap(
unsigned int one,
unsigned int two){
111 HT_TYPE temp=(*this)[one];
112 (*this)[one]=(*this)[two];
130 vector<HT_TYPE>::resize(unsortedCount+1);
131 (*this)[unsortedCount]=value;
133 int index=unsortedCount;
136 int parent=findParent(index);
137 if ((*
this)[parent]<(*
this)[index]){
152 findCell(&(*
this)[index], cell);
160 HT_TYPE* root=&(*this)[0];
162 int location = (int)(index-root);
165 while ((location-=(
int)pow(base,(
float)cell.
level))>=0)
167 location+=(
int)pow(base,(
float)cell.
level);
177 if (!cell.
level)
return 0;
178 return (
unsigned int)(pow(base,(
float)cell.
level)+cell.
child-base+1.0);
187 cerr<<
"error: the root parent has no parent"<<endl;
191 findCell(index, child);
193 parent.
child=(
unsigned int)floor((
float)child.
child/base);
194 return findIndex(parent);
205 findCell(parent, cell);
220 cout<<(*
this)[i]<<
'\t';
227 cout<<*((*
this)[i])<<
'\t';
234 unsigned int myIndex=findIndex(cell);
235 findChildren(myIndex, childL, childR);
236 if (findIndex(childL)<=unsortedCount)
238 cout<<(*this)[myIndex]<<
'\t';
239 if (findIndex(childR)<=unsortedCount)
247 unsigned int unsortedCountOrig=unsortedCount;
248 while (unsortedCount>0){
249 unsigned int index=0;
250 swap(index,unsortedCount);
259 void resize(
size_t s, HT_TYPE c=HT_TYPE()){
260 vector<HT_TYPE>::resize(s,c);
296 #endif //HEAP_TREE_TYPE_H_
unsigned int child
The numeric count of the child in the tree from the top.
void findChildren(unsigned int parent, HeapTreeCell &childL, HeapTreeCell &childR)
void swap(unsigned int one, unsigned int two)
unsigned int findIndex(HeapTreeCell &cell)
void findCell(HT_TYPE *index, HeapTreeCell &cell)
void swapIfBigger(unsigned int index)
void resize(size_t s, HT_TYPE c=HT_TYPE())
unsigned int level
The level of the tree which is pointed to, from the top.
virtual void deleteElements(void)
HeapTreeType(int baseIn=2)
Constructor - currrently only supports baseIn=2 : to be expanded in the future.
unsigned int findParent(unsigned int index)
void dumpLPR(HeapTreeCell &cell)
void findCell(unsigned int index, HeapTreeCell &cell)