DSA Hacking Club Library
Loading...
Searching...
No Matches
queue.h File Reference

A simple linked-list-based queue implementation in C. More...

#include <stdbool.h>
Include dependency graph for queue.h:

Go to the source code of this file.

Classes

struct  node
 A node in the singly linked list. More...
struct  queue
 Queue structure. More...

Macros

#define QUEUE_EMPTY   (-1)
 Return code for dequeue when the queue is empty.

Typedefs

typedef struct node node_t
 Node structure for the queue.

Functions

void init_queue (queue *q)
 Initialize a queue.
bool enqueue (queue *q, int value)
 Insert a new value at the end of the queue.
int dequeue (queue *q)
 Remove and return the value at the front of the queue.
void printqueue (queue *q)
 Print the contents of the queue to stdout.

Detailed Description

A simple linked-list-based queue implementation in C.

Author
Alifoo
Date
2025-09-25

This header defines the queue structure and its operations such as initialization, enqueue, dequeue, and printing. The queue stores integers.

Typedef Documentation

◆ node_t

typedef struct node node_t

Node structure for the queue.

Each node stores an integer value and a pointer to the next node.

Function Documentation

◆ dequeue()

int dequeue ( queue * q)

Remove and return the value at the front of the queue.

Parameters
[in,out]qPointer to the queue.
Returns
The dequeued value, or QUEUE_EMPTY if the queue is empty.

◆ enqueue()

bool enqueue ( queue * q,
int value )

Insert a new value at the end of the queue.

Parameters
[in,out]qPointer to the queue.
[in]valueThe integer value to enqueue.
Returns
true if the value was enqueued successfully, false on memory allocation failure.

◆ init_queue()

void init_queue ( queue * q)

Initialize a queue.

Sets the head and tail pointers of the queue to NULL.

Parameters
[in,out]qPointer to the queue to initialize.

◆ printqueue()

void printqueue ( queue * q)

Print the contents of the queue to stdout.

Each value is printed on a separate line with the format: "t = <value>".

Parameters
[in]qPointer to the queue.