https://github.com/usmanmehmood55/queue
A queue implementation in C
https://github.com/usmanmehmood55/queue
buffer c data-structures queue
Last synced: about 1 year ago
JSON representation
A queue implementation in C
- Host: GitHub
- URL: https://github.com/usmanmehmood55/queue
- Owner: usmanmehmood55
- License: mit
- Created: 2022-04-16T18:29:09.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-09-05T14:19:35.000Z (over 2 years ago)
- Last Synced: 2025-01-04T09:04:33.297Z (about 1 year ago)
- Topics: buffer, c, data-structures, queue
- Language: C
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Queue
An implementation of a queue in C. Most of the code is based on the implementation
found in [this article](https://www.geeksforgeeks.org/queue-set-1introduction-and-array-implementation/).
[](https://github.com/usmanmehmood55/queue/actions/workflows/build_and_test.yml)
[](https://codecov.io/gh/usmanmehmood55/queue)
## Usage
The queue is implemented as a structure with the front, rear, size, and an array.
```c
typedef struct queue_t
{
uint16_t front;
uint16_t rear;
uint16_t size;
uint16_t capacity;
uint16_t * elements;
} queue_t;
```
The user can enqueue items in it until the capacity is filled. After which old
items must be dequeued to enqueue new ones.
A queue with capacity `5` can be initialized like this.
```c
queue_t *q = NULL;
int err = queue_create(&q, 5U);
if (err != 0)
{
// error handling
}
```
After use, the queue can be de-initialized like this.
```c
err = queue_destroy(q)
if (err != 0)
{
// error handling
}
```