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];
129 if (unsortedCount+1>vector<HT_TYPE>::size())
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);
194 return findIndex(parent);
205 findCell(parent, cell);
219 for (
int i=0;i<vector<HT_TYPE>::size();i++)
220 cout<<(*
this)[i]<<
'\t';
226 for (
int i=0;i<vector<HT_TYPE>::size();i++)
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_