Skip to content

lanstobias/circular-queue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Circular Queue implementation in C

Design

Here's the internal structure of the datatype

typedef struct
{
    int rear, front;
    int* array;
    int size;
    int nrOfElements;
} queue;

Methods

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

// 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

$ 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! :)

About

Implementation of a circular queue in c

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published