|
C Fundamentals
Algorithms · data structures · cryptography · systems — pure C11, zero deps
|
LIFO stack of int, backed by a growable dynamic array.
More...
#include <stdbool.h>#include <stddef.h>Go to the source code of this file.
Typedefs | |
| typedef struct cf_stack | cf_stack_t |
Functions | |
| cf_stack_t * | cf_stack_create (void) |
| void | cf_stack_destroy (cf_stack_t *s) |
| bool | cf_stack_is_empty (const cf_stack_t *s) |
| bool | cf_stack_peek (const cf_stack_t *s, int *out_value) |
| bool | cf_stack_pop (cf_stack_t *s, int *out_value) |
| bool | cf_stack_push (cf_stack_t *s, int value) |
| size_t | cf_stack_size (const cf_stack_t *s) |
LIFO stack of int, backed by a growable dynamic array.
Resize policy: doubles when full, never shrinks. push/pop/peek are O(1) amortised; size and is_empty are O(1).
Note: type is named cf_stack_t (rather than stack_t) to avoid collision with POSIX stack_t from <signal.h> / <sys/_types.h>, which is dragged in transitively by stdlib.h on macOS.
Definition in file stack.h.
| typedef struct cf_stack cf_stack_t |
| cf_stack_t * cf_stack_create | ( | void | ) |
Definition at line 16 of file stack.c.
References cf_stack::capacity, CF_STACK_INITIAL_CAP, cf_stack::data, and cf_stack::size.
| void cf_stack_destroy | ( | cf_stack_t * | s | ) |
Definition at line 26 of file stack.c.
References cf_stack::data.
| bool cf_stack_is_empty | ( | const cf_stack_t * | s | ) |
Definition at line 59 of file stack.c.
References cf_stack::size.
| bool cf_stack_peek | ( | const cf_stack_t * | s, |
| int * | out_value | ||
| ) |
Definition at line 52 of file stack.c.
References cf_stack::data, and cf_stack::size.
| bool cf_stack_pop | ( | cf_stack_t * | s, |
| int * | out_value | ||
| ) |
Definition at line 45 of file stack.c.
References cf_stack::data, and cf_stack::size.
| bool cf_stack_push | ( | cf_stack_t * | s, |
| int | value | ||
| ) |
Definition at line 32 of file stack.c.
References cf_stack::capacity, cf_stack::data, and cf_stack::size.
| size_t cf_stack_size | ( | const cf_stack_t * | s | ) |
Definition at line 58 of file stack.c.
References cf_stack::size.