#include "queue.h" //------------- private ----------------------- #define MAX_QUEUE_SIZE 10 int first = 0; int last = 0; int size = 0; QueueElement theQueue[MAX_QUEUE_SIZE]; int nextPos(int currentPos) { //The next position is 0 if the current position is at the end of the array. return ++currentPos % MAX_QUEUE_SIZE; } //-------------------- public --------------- int enqueue(QueueElement element) { if (size == MAX_QUEUE_SIZE) { //The queue is full, return error code (-1). return -1; } else { //The queue is not full. Enqueue and return success code (0). size++; theQueue[last] = element; last = nextPos(last); return 0; } } int dequeue(QueueElement *element) { if (size == 0) { //The queue is empty, return error code (-1). return -1; } else { //The queue is not empty. Dequeue and return success code (0). size--; *element = theQueue[first]; first = nextPos(first); return 0; } }