This library provides functions for the creation and manipulation of stacks.
More...
This library provides functions for the creation and manipulation of stacks.
The library is implemented as a wrapper around the list library.
A stack is declared using the STACK macro. Stack elements must be allocated by the calling code and must be of a C struct datatype. In this struct, the first field must be a pointer called next. This field will be used by the library to maintain the stack. Application code must not modify this field directly.
◆ STACK
#define STACK |
( |
|
name | ) |
LIST(name) |
Define a stack.
This macro defines a stack.
The datatype for elements must be a C struct. The struct's first member must be a pointer called next. This is used internally by the library to maintain data structure integrity and must not be modified directly by application code.
- Parameters
-
name | The name of the stack. |
Definition at line 75 of file stack.h.
◆ stack_init()
static void stack_init |
( |
stack_t |
stack | ) |
|
|
inlinestatic |
Initialise a stack.
- Parameters
-
Definition at line 86 of file stack.h.
◆ stack_is_empty()
static bool stack_is_empty |
( |
stack_t |
stack | ) |
|
|
inlinestatic |
Check if a stack is empty.
- Parameters
-
- Return values
-
true | The stack is empty |
false | The stack has at least one element |
Definition at line 133 of file stack.h.
◆ stack_peek()
static void* stack_peek |
( |
stack_t |
stack | ) |
|
|
inlinestatic |
Returns the top element of the stack, without popping it.
- Parameters
-
- Returns
- A pointer to the element at the top of the stack
Definition at line 121 of file stack.h.
◆ stack_pop()
static void* stack_pop |
( |
stack_t |
stack | ) |
|
|
inlinestatic |
Removes the top element from the stack.
- Parameters
-
- Returns
- A pointer to the element popped
If this function returns NULL if the stack was empty (stack underflow)
Definition at line 110 of file stack.h.
◆ stack_push()
static void stack_push |
( |
stack_t |
stack, |
|
|
void * |
element |
|
) |
| |
|
inlinestatic |
Adds an element to the top of the stack.
- Parameters
-
stack | The stack |
element | A pointer to the element to be added |
Definition at line 97 of file stack.h.