1 # ifndef TPL_DYNARRAYHEAP_H
2 # define TPL_DYNARRAYHEAP_H
4 # include <tpl_dynArray.H>
9 template <
typename T,
class Compare>
inline
12 for (
size_t p, i = r; i > l; i = p)
17 if (Compare () (ap, ai))
24 template <
typename T,
class Compare>
inline
37 T * ac1 = & a.
access(c + 1);
38 if (Compare () (*ac1, *ac))
46 if (Compare () (ai, *ac))
68 template <
typename T,
class Compare = Aleph::less<T>>
74 static size_t r_index(
const size_t & i)
93 T &
top() throw(std::exception, std::underflow_error)
96 throw std::underflow_error(
"Heap is empty");
98 return array.access(1);
110 T &
insert(
const T & key)
throw(std::exception, std::overflow_error)
112 array.touch(++num_items) = key;
113 sift_up<T,Compare>(array, 1, num_items);
114 return array.access(num_items);
126 T
getMin() throw(std::exception, std::underflow_error)
129 throw std::underflow_error(
"Heap is empty");
131 T & a1 = array.access(1);
133 a1 = array[num_items--];
134 sift_down<T,Compare>(array, 1, num_items);
136 array.cut(num_items + 1);
142 T
get()
throw(std::exception, std::underflow_error)
148 T
getMax() throw(std::exception, std::underflow_error)
154 const size_t &
size()
const {
return num_items; }
164 # endif // TPL_DYNARRAYHEAP_H
Definition: tpl_dynArrayHeap.H:69
T getMin()
Definition: tpl_dynArrayHeap.H:126
bool is_empty() const
Retorna true si el heap está vacío.
Definition: tpl_dynArrayHeap.H:157
T & insert(const T &key)
Definition: tpl_dynArrayHeap.H:110
T & top()
Retorna el menor elemento del heap.
Definition: tpl_dynArrayHeap.H:93
T getMax()
Definition: tpl_dynArrayHeap.H:148
Definition: tpl_dynArray.H:70
DynArrayHeap(Compare &)
Constructor con dimensión por omisión.
Definition: tpl_dynArrayHeap.H:82
T & access(const size_t i)
Definition: tpl_dynArray.H:793
const size_t & size() const
Retorna la cantidad de elementos.
Definition: tpl_dynArrayHeap.H:154