#include <stdbool.h>
#include <stddef.h>
Go to the source code of this file.
|
| void | queue_init (Queue *queue, size_t element_size) |
| | Initializes an empty Queue.
|
| |
| void | queue_destroy (Queue *queue) |
| | Destroys the Queue and frees all allocated nodes and their associated data.
|
| |
| bool | queue_push (Queue *queue, const void *data) |
| | Enqueues (pushes) a new element to the back of the queue.
|
| |
| bool | queue_pop (Queue *queue) |
| | Dequeues (removes) the element at the front of the queue.
|
| |
| void * | queue_front (Queue *queue) |
| | Accesses the element at the front of the queue without removing it.
|
| |
| void * | queue_back (Queue *queue) |
| | Accesses the element at the back of the queue without removing it.
|
| |
| int | queue_search (Queue *queue, int(*cmp_fn)(void *, void *), void *key) |
| | Searches for an element in the queue using a comparison function.
|
| |
| int | queue_size (const Queue *queue) |
| | Retrieves the total number of elements currently stored in the queue.
|
| |
◆ QueueNode
Node structure representing an element in the queue.
◆ queue_back()
| void * queue_back |
( |
Queue * |
queue | ) |
|
Accesses the element at the back of the queue without removing it.
- Parameters
-
| queue | Pointer to the Queue. |
- Returns
- Pointer to the data at the back of the queue, or NULL if the queue is empty.
◆ queue_destroy()
| void queue_destroy |
( |
Queue * |
queue | ) |
|
Destroys the Queue and frees all allocated nodes and their associated data.
- Parameters
-
| queue | Pointer to the Queue to destroy. |
◆ queue_front()
| void * queue_front |
( |
Queue * |
queue | ) |
|
Accesses the element at the front of the queue without removing it.
- Parameters
-
| queue | Pointer to the Queue. |
- Returns
- Pointer to the data at the front of the queue, or NULL if the queue is empty.
◆ queue_init()
| void queue_init |
( |
Queue * |
queue, |
|
|
size_t |
element_size |
|
) |
| |
Initializes an empty Queue.
- Parameters
-
| queue | Pointer to the Queue structure to initialize. |
| element_size | Size of each element in bytes. |
◆ queue_pop()
| bool queue_pop |
( |
Queue * |
queue | ) |
|
Dequeues (removes) the element at the front of the queue.
- Parameters
-
| queue | Pointer to the Queue. |
- Returns
true if an element was successfully removed, or false if the queue was empty.
◆ queue_push()
| bool queue_push |
( |
Queue * |
queue, |
|
|
const void * |
data |
|
) |
| |
Enqueues (pushes) a new element to the back of the queue.
- Parameters
-
| queue | Pointer to the Queue. |
| data | Pointer to the element data to insert. |
- Returns
true if insertion was successful, or false on memory allocation failure.
◆ queue_search()
| int queue_search |
( |
Queue * |
queue, |
|
|
int(*)(void *, void *) |
cmp_fn, |
|
|
void * |
key |
|
) |
| |
Searches for an element in the queue using a comparison function.
- Parameters
-
| queue | Pointer to the Queue. |
| cmp_fn | Pointer to the comparison function (should return 0 when elements match). |
| key | Pointer to the value/key being searched for. |
- Returns
- The zero-based index of the element if found, or -1 if not found.
◆ queue_size()
| int queue_size |
( |
const Queue * |
queue | ) |
|
Retrieves the total number of elements currently stored in the queue.
- Parameters
-
| queue | Pointer to the Queue. |
- Returns
- Total number of elements.