osurs  0.0.1
Functions
queue.c File Reference

Queue data structure. More...

#include "osurs/ds/queue.h"
#include <stdio.h>
#include <stdlib.h>
Include dependency graph for queue.c:

Functions

void queue_init (Queue *queue)
 Initialize a Queue structure. More...
 
Queuequeue_create ()
 Create a new Queue structure. More...
 
void queue_enqueue (Queue *queue, void *data)
 Add an element to the end of a Queue. More...
 
void * queue_dequeue (Queue *queue)
 Remove an element from the front of a Queue. More...
 
bool queue_is_empty (Queue *queue)
 Check if a Queue is empty. More...
 
void queue_clear (Queue *queue)
 Clear all elements from a Queue. More...
 
void queue_free (Queue *queue)
 Free a Queue structure. More...
 

Detailed Description

Queue data structure.

Date
: 2022-12-20
Author
: Merlin Unterfinger

Function Documentation

◆ queue_clear()

void queue_clear ( Queue queue)

Clear all elements from a Queue.

This function removes all elements from a Queue, but does not free the queue structure itself.

Parameters
queueThe Queue to be cleared.

◆ queue_create()

Queue* queue_create ( )

Create a new Queue structure.

This function creates a new Queue structure and returns a pointer to it. The new structure is initialized with its head and tail pointers set to NULL.

Returns
A pointer to the new Queue structure.

◆ queue_dequeue()

void* queue_dequeue ( Queue queue)

Remove an element from the front of a Queue.

This function removes the element at the front of a Queue and returns a pointer to it. If the queue is empty, the function returns NULL.

Parameters
queueThe Queue from which the element will be removed.
Returns
The element at the front of the queue, or NULL if the queue is empty.

◆ queue_enqueue()

void queue_enqueue ( Queue queue,
void *  data 
)

Add an element to the end of a Queue.

This function adds an element to the end of a Queue. If the queue is empty, the element becomes both the head and the tail of the queue.

Parameters
queueThe Queue to which the element will be added.
dataThe element to be added to the queue.

◆ queue_free()

void queue_free ( Queue queue)

Free a Queue structure.

This function frees a Queue structure, including all nodes and their data.

Parameters
queueThe Queue structure to be freed.

◆ queue_init()

void queue_init ( Queue queue)

Initialize a Queue structure.

This function initializes a Queue structure by setting its head and tail pointers to NULL.

Parameters
queueThe Queue structure to be initialized.

◆ queue_is_empty()

bool queue_is_empty ( Queue queue)

Check if a Queue is empty.

This function checks if a Queue is empty (contains no elements).

Parameters
queueThe Queue to be checked.
Returns
true if the queue is empty, false otherwise.