52int main(
int argc,
char *argv[])
57 try { n = stoi(argv[1]); }
catch (...) { n = 1000; }
62 cerr <<
"n must be positive" << endl;
66 unsigned int t = std::time(0);
69 try { t = stoul(argv[2]); }
catch (...) { t = std::time(0); }
74 cout <<
"testBinHeap " << n <<
" " << t << endl;
80 for (i = n - 1; i >= 0; i--)
88 for (i = 0; i < n; i++)
98 for (i = n - 1; i >= 0; i--)
100 value = (int) (n*100.0*rand()/(RAND_MAX+1.0));
103 cout <<
value <<
" ";
109 for (i = 0; i < n; i++)
116 assert(heap.
size() == 0);
118 for (i = n - 1; i >= 0; i--)
120 value = (int) (n*100.0*rand()/(RAND_MAX+1.0));
127 for (i = 0; i < n/2; i++)
134 for (i = n - 1; i >= 0; i--)
136 value = (int) (n*100.0*rand()/(RAND_MAX+1.0));
142 for (i = 0; i <= n + n/2; i++)
149 catch (exception & e)
151 cout << e.what() << endl;
155 assert(heap.
size() == 0);
161 for (i = 2*n - 1; i >= 0; i--)
170 for (i = 0; i < n/2; i++)
172 value = (int) (1.0*n*rand()/(RAND_MAX+1.0));
185 for (i = 0; i < n/2; i++)
187 value = (int) (n*100.0*rand()/(RAND_MAX+1.0));
195 while (heap.
size() > 0)
202 assert(heap.
size() == 0);
204 for (i = n - 1; i >= 0; i--)
211 for (i = 0; i < n; i++)
217 assert(heap.
size() == 0);
219 cout <<
"End" << endl;
Core header for the Aleph-w library.
size_t size_t int32_t value
Node * insert(Node *p) noexcept(nothrow_cmp)
Inserts a node into a 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.
Node * remove(Node *node)
Removes node from the heap.
void remove_all_and_delete() noexcept
Deletes all the nodes of the heap, invokes the destructors of the removed nodes, and frees all the me...
Node * getMin()
Removes the node with the lowest priority from the heap.
const size_t & size() const noexcept
DynArray< Graph::Node * > nodes
Main namespace for Aleph-w library functions.
Node heap without virtual destructor.
BinHeapNode< Key > Node
The heap's node type.
static void printNode(BinHeap< int >::Node *node, int, int)
Binary heap implementation using tree structure.
Utility functions for binary tree operations.
Lazy and scalable dynamic array implementation.