C Fundamentals
Algorithms · data structures · cryptography · systems — pure C11, zero deps
Loading...
Searching...
No Matches
stack.h
Go to the documentation of this file.
1/**
2 * @file stack.h
3 * @brief LIFO stack of `int`, backed by a growable dynamic array.
4 *
5 * Resize policy: doubles when full, never shrinks. push/pop/peek are
6 * O(1) amortised; size and is_empty are O(1).
7 *
8 * Note: type is named `cf_stack_t` (rather than `stack_t`) to avoid
9 * collision with POSIX `stack_t` from `<signal.h>` / `<sys/_types.h>`,
10 * which is dragged in transitively by stdlib.h on macOS.
11 */
12
13#ifndef CF_STACK_H
14#define CF_STACK_H
15
16#include <stdbool.h>
17#include <stddef.h>
18
19typedef struct cf_stack cf_stack_t;
20
23
24bool cf_stack_push(cf_stack_t *s, int value);
25bool cf_stack_pop(cf_stack_t *s, int *out_value);
26bool cf_stack_peek(const cf_stack_t *s, int *out_value);
27
28size_t cf_stack_size(const cf_stack_t *s);
29bool cf_stack_is_empty(const cf_stack_t *s);
30
31#endif /* CF_STACK_H */
bool cf_stack_pop(cf_stack_t *s, int *out_value)
Definition stack.c:45
bool cf_stack_is_empty(const cf_stack_t *s)
Definition stack.c:59
bool cf_stack_peek(const cf_stack_t *s, int *out_value)
Definition stack.c:52
void cf_stack_destroy(cf_stack_t *s)
Definition stack.c:26
size_t cf_stack_size(const cf_stack_t *s)
Definition stack.c:58
cf_stack_t * cf_stack_create(void)
Definition stack.c:16
bool cf_stack_push(cf_stack_t *s, int value)
Definition stack.c:32