https://github.com/lanstobias/circular-queue
Implementation of a circular queue in c
https://github.com/lanstobias/circular-queue
adt c circular-queue linux queue
Last synced: 6 months ago
JSON representation
Implementation of a circular queue in c
- Host: GitHub
- URL: https://github.com/lanstobias/circular-queue
- Owner: lanstobias
- License: mit
- Created: 2018-05-07T07:50:52.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-05-07T08:30:31.000Z (over 7 years ago)
- Last Synced: 2025-01-09T07:50:33.142Z (about 1 year ago)
- Topics: adt, c, circular-queue, linux, queue
- Language: C
- Homepage:
- Size: 6.84 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Circular Queue implementation in C
## Design
Here's the internal structure of the datatype
```c
typedef struct
{
int rear, front;
int* array;
int size;
int nrOfElements;
} queue;
```
Methods
```c
int queueDequeue(queue* self);
int queueEnqueue(queue* self, int value);
void queueClear(queue* self);
int queueIsFull(queue* self);
int queueIsEmpty(queue* self);
int queueSize(queue* self);
int queueFirst(queue* self);
int queueLast(queue* self);
```
## Usage
```c
// Create queue object
queue queue;
// Initialize the queue with given size
queueInit(&queue, 100);
// Add values to the queue
queueEnqueue(&queue, 2);
queueEnqueue(&queue, 4);
queueEnqueue(&queue, 6);
// Get first in queue
int dequeueVal = queueDequeue(&queue); // <-- 2
```
## Tests
There are tests for all methods. To create the executable tests file, run the make command
```shell
$ make tests
```
You can then execute the test file as shown below
```
$ ./tests
Testing newQueue().. passed!
Testing queueSize().. passed!
Testing queueEnqueue().. passed!
Testing queueDequeue().. passed!
Testing queueClear().. passed!
Testing queueFirst().. passed!
Testing queueLast().. passed!
Testing queueIsFull().. passed!
Testing queueIsEmpty().. passed!
All tests passed! :)
```