Name

stack_init

Synopsis

void stack_init(Stack *stack, void (*destroy)(void *data));

Return Value

None.

Description

Initializes the stack specified by stack. This operation must be called for a stack before the stack can be used with any other operation. The destroy argument provides a way to free dynamically allocated data when stack_destroy is called. For example, if the stack contains data dynamically allocated using malloc, destroy should be set to free to free the data as the stack is destroyed. For structured data containing several dynamically allocated members, destroy should be set to a user-defined function that calls free for each dynamically allocated member as well as for the structure itself. For a stack containing data that should not be freed, destroy should be set to NULL.

Complexity

O (1)

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.