Stack data structure.
More...
#include "osurs/ds/stack.h"
#include <stdio.h>
#include <stdlib.h>
Stack data structure.
- Date
- : 2022-12-21
- Author
- : Merlin Unterfinger
◆ stack_clear()
void stack_clear |
( |
Stack * |
stack | ) |
|
Clear all elements from a Stack.
This function removes all elements from a Stack, but does not free the stack structure itself.
- Parameters
-
stack | The Stack to be cleared. |
◆ stack_create()
Create a new Stack structure.
This function creates a new Stack structure and returns a pointer to it. The new structure is initialized with its top pointer set to NULL and its size set to 0.
- Returns
- A pointer to the new Stack structure.
◆ stack_free()
void stack_free |
( |
Stack * |
stack | ) |
|
Free a Stack structure.
This function frees a Stack structure, including all nodes and their data.
- Parameters
-
stack | The Stack structure to be freed. |
◆ stack_init()
void stack_init |
( |
Stack * |
stack | ) |
|
Initialize a Stack structure.
This function initializes a Stack structure by setting its top pointer to NULL and its size to 0.
- Parameters
-
stack | The Stack structure to be initialized. |
◆ stack_is_empty()
bool stack_is_empty |
( |
Stack * |
stack | ) |
|
Check if a Stack is empty.
This function checks if a Stack is empty (contains no elements).
- Parameters
-
stack | The Stack to be checked. |
- Returns
- true if the stack is empty, false otherwise.
◆ stack_peek()
void* stack_peek |
( |
Stack * |
stack | ) |
|
Return the top element of a Stack.
This function returns a pointer to the element at the top of a Stack, without removing it from the stack. If the stack is empty, the function returns NULL.
- Parameters
-
stack | The Stack from which the top element will be returned. |
- Returns
- The element at the top of the stack, or NULL if the stack is empty.
◆ stack_pop()
void* stack_pop |
( |
Stack * |
stack | ) |
|
Pop the top element from a Stack.
This function removes the element at the top of a Stack and returns a pointer to it. If the stack is empty, the function returns NULL.
- Parameters
-
stack | The Stack from which the element will be removed. |
- Returns
- The element at the top of the stack, or NULL if the stack is empty.
◆ stack_push()
void stack_push |
( |
Stack * |
stack, |
|
|
void * |
data |
|
) |
| |
Push an element onto a Stack.
This function pushes an element onto the top of a Stack.
- Parameters
-
stack | The Stack onto which the element will be pushed. |
data | The element to be pushed onto the stack. |