A queue is a list with the restriction that you can insert at the front of the list and you can delete at the end of the list.
typedef struct{
int que[size];
int front;
int rear;
} Queue;
The actual array of Queue.
The front of the Queue, this is where you ### [EnQueue] in the Queue. front starts at index 0.
The rear of the Queue, this is where you ### [DeQueue] in the Queue. rear starts at index -1.
The function increases rear and inserts a value in that index.
void EnQueue(Queue* queue, int val){
queue->rear += 1;
queue->que[queue->rear] = val;
}
The function saves front in data; increments front; and returns data.
int DeQueue(Queue* queue){
int data queue->que[queue->front];
queue->front += 1;
return data;
}
The function check if the Queue is full by checking if rear is equal to size.
bool isFull(int rear){
bool full = false;
if(rear == size-1)
full = true;
return true;
}
The function check if the Queue is empty by checking if front is greater than rear.
bool isEmpty(int rear){
bool empty = false;
if(rear+1 == front)
empty = true;
return true;
}