42int keys [] = { 36, 32, 4, 12, 52, 59, 2, 2, 26, 1 };
51 std::memset(
buf, 0,
sizeof(
buf));
56 virtual void foo() = 0;
94int main(
int argc,
char* argv[])
101 n =
static_cast<unsigned int>(atoi(argv[1]));
104 cout <<
"Testing with predefined keys array" << endl;
110 cout <<
"Predefined keys heap size: " << heap.
size() << endl;
115 unsigned int i,
value;
117 for (i = 0; i < n; i++)
119 value = (
unsigned int) ((10.0*n*rand())/(RAND_MAX+1.0));
120 cout <<
value <<
", ";
127 <<
"Sum = " << heap.
fold(0, [] (
const int acu,
const int i)
136 cout <<
"testing with pointers" << endl;
139 unsigned int i,
value;
142 for (i = 0; i < n; i++)
144 value = (
unsigned int) ((10.0*n*rand())/(RAND_MAX+1.0));
145 ptr =
new unsigned int;
147 cout <<
value <<
", ";
152 <<
"Extracting from heap" << endl;
154 for (i = 0; i < n; i++)
158 cout <<
value <<
" ";
166 cout <<
"testing with pointers to record" << endl;
169 unsigned int i,
value;
172 for (i = 0; i < n; i++)
174 value = (
unsigned int) ((10.0*n*rand())/(RAND_MAX+1.0));
176 cout <<
value <<
", ";
181 <<
"Extracting from heap" << endl;
183 for (i = 0; i < n; i++)
187 cout <<
value <<
" ";
#define MESSAGE(...)
Print an informational message (no-op when MESSAGES is not defined).
size_t size_t int32_t value
Dynamic heap of elements of type T ordered by a comparison functor.
T getMin()
Remove the minimum element (according to Compare) and return it.
T & insert(const T &item)
Insert a copy of item into the heap.
virtual bool verify_heap(Node *p) const
Whether no node of the tree of root p has a key less than that of its parent.
const size_t & size() const noexcept
T fold(const T &init, Operation &operation) const
Simplified version of foldl() where the folded type is the same type of elements stored in the contai...
bool operator()(unsigned int *p1, unsigned int *p2) const
bool operator()(const Record &l, const Record &r) const
Dynamic binary heap with node-based storage.