Name

heap_insert

Synopsis

int heap_insert(Heap *heap, const void *data);

Return Value

0 if inserting the node is successful, or -1 otherwise.

Description

Inserts a node into the heap specified by heap. The new node contains a pointer to data, so the memory referenced by data should remain valid as long as the node remains in the heap. It is the responsibility of the caller to manage the storage associated with data.

Complexity

O (lg n), where n is the number of nodes in the heap.

Get Mastering Algorithms with C now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.