osurs  0.0.1
Data Structures | Typedefs | Functions
queue.h File Reference

Queue data structure. More...

#include <stdbool.h>
Include dependency graph for queue.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  QueueNode
 Queue node. More...
 
struct  Queue
 Queue. More...
 

Typedefs

typedef struct QueueNode QueueNode
 Queue node. More...
 
typedef struct Queue Queue
 Queue. More...
 

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.

This file defines a Queue data structure, which is an abstract data type (ADT) that implements a FIFO (first-in, first-out) queue. Elements can be inserted at one end (tail) and removed from the other end (head).

Date
2022-12-20
Author
Merlin Unterfinger

Typedef Documentation

◆ Queue

typedef struct Queue Queue

Queue.

This structure represents a Queue data structure. It consists of pointers to the head and tail of the queue (the nodes at the front and back of the queue, respectively).

◆ QueueNode

typedef struct QueueNode QueueNode

Queue node.

This structure represents a node in a Queue data structure. It consists of a void pointer to the node's data and a pointer to the next node in the queue.

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.