36 template <
class T,
class CT,
class IT>
37 std::ostream& operator << (std::ostream& s, const IndexedHeap<T,CT,IT>& t)
40 for (
int i=0; i<t.size(); i++) s << t[i] <<
" " ;
48 template <
class T,
class CT,
class IT>
49 IndexedHeap<T,CT,IT>::IndexedHeap (
const CT& comp,
const IT& index )
50 : m_c(&comp), m_i(&index)
56 template <
class T,
class CT,
class IT>
64 template <
class T,
class CT,
class IT>
73 template <
class T,
class CT,
class IT>
74 int IndexedHeap<T,CT,IT>::insert(T t)
78 return upsort(size()-1);
83 template <
class T,
class CT,
class IT>
84 T& IndexedHeap<T,CT,IT>::top()
93 template <
class T,
class CT,
class IT>
94 const T& IndexedHeap<T,CT,IT>::top()
const
102 template <
class T,
class CT,
class IT>
103 T IndexedHeap<T,CT,IT>::remove_top()
123 template <
class T,
class CT,
class IT>
124 T IndexedHeap<T,CT,IT>::remove(
int n)
143 template <
class T,
class CT,
class IT>
144 void IndexedHeap<T,CT,IT>::clear()
146 for (
typename std::vector<T>::iterator i=m_p.begin(); i!=m_p.end(); ++i)
156 template <
class T,
class CT,
class IT>
157 int IndexedHeap<T,CT,IT>::father(
int i)
const
164 template <
class T,
class CT,
class IT>
165 int IndexedHeap<T,CT,IT>::rightson(
int i)
const
172 template <
class T,
class CT,
class IT>
173 int IndexedHeap<T,CT,IT>::leftson(
int i)
const
180 template <
class T,
class CT,
class IT>
181 void IndexedHeap<T,CT,IT>::swap(
int i,
int j)
195 template <
class T,
class CT,
class IT>
196 int IndexedHeap<T,CT,IT>::upsort(
int i)
200 while ((i>0)&&(*m_c)(m_p[i],m_p[j]))
212 template <
class T,
class CT,
class IT>
213 int IndexedHeap<T,CT,IT>::downsort(
int i)
218 unsigned int ls = leftson(i);
221 bool lc = ((*m_c)(m_p[i],m_p[ls]));
222 unsigned int rs = ls + 1;
224 if (rs<m_p.size()) rc = ((*m_c)(m_p[i],m_p[rs]));
229 if ((*m_c)(m_p[ls],m_p[rs]))