Name

bistree_insert

Synopsis

int bistree_insert(BisTree *tree, const void *data);

Return Value

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

Description

Inserts a node into the binary search tree specified by tree. 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 binary search tree. 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 binary search tree.

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.