Nodes can be inserted and deleted in a chain either at one end of the chain, or in a sorted fashion. This allows chains to behave as sorted linked lists, queues, or stacks.
Creates a node containing data and inserts it at the correct place in chain, such that chain remains sorted increasing according to compare. cmp_args is passed as the last argument to cmp. Returns a pointer to the node thus created, or a null pointer if there was insufficient memory.
To use a chain as a stack, insertion and deletion of nodes must be performed only at one end of the chain; the functions here alter the chain only at the front.
Creates a node containing data and inserts it at the front of chain. Returns a pointer to the chainlink thus created, or a null pointer if there was insufficient memory.
Removes the node at the front of chain, returning the result of applying ‘chainlink_data’ to that node. chain must contain at least one node.
Removes the node at the front of chain. Note that this function provides no way to free any dynamically-allocated data stored in that node. chain must contain at least one node.
Returns a reference to the first node in chain; that is, the node which is the top of the stack. If there are no nodes in chain, a null pointer is returned. This function is equivalent to ‘chain_front’.
To use a chain as a queue, insertions are performed only at the back of the chain, while deletions are performed only at the front.
Creates a node containing data and inserts it at the end of chain. Returns a pointer to the node thus created, or a null pointer if there was insufficient memory.
Removes the node at the front of chain, returning the result of applying ‘chainlink_data’ to that node. chain must contain at least one node. This function is equivalent to ‘chain_pop’.
It is also possible to specify explicitly the end at which an insertion or deletion is to be performed.
Creates a node containing data and inserts it at the front of chain. Returns a pointer to the node thus created, or a null pointer if there was insufficient memory.
Removes the node at the front of chain, returning the result of applying ‘chainlink_data’ to that node. chain must contain at least one node.
Creates a new node containing data and inserts it at the end of chain. Returns a pointer to the node thus created, or a null pointer if there was insufficient memory. ‘chain_append’ is a synonym for ‘chain_back_insert’.
Removes the node at the end of chain, returning the result of applying ‘chainlink_data’ to that node. chain must contain at least one node.
Move node to the front or back respectively of chain. node must be a member of chain.1
Removes node from chain. node must be a member of chain. The contents of node are undefined on return.
It is also possible to selectively delete more than one object in a chain at once. This requires a `pruning' function.
int (*) (void *
obj, void *
args)
The type of a function pointer used to determine whether to delete objects in a chain. It is passed a reference to the contents of an element in obj, as well as a pointer to user-supplied arguments in args. It should return zero if and only if the element should not be deleted. Note that if the elements of a chain were dynamically allocated, it is probably a good idea to make the pruning function free this dynamically allocated memory.
Deletes any objects in chain for which pruner is true. prune_args is passed as the last argument to pruner.
[1] These functions qualify as `insertion and deletion functions' by virtue of the fact that they correspond to a deletion and insertion performed in one operation.