Array representation of queue
A queue can be represented using linear arrays. Two variables, namely the front and end are implemented in the case of arrays. They point to the position where insertions and deletions are performed.
Algorithm for insertion in queue:

C program:
void insert (int queue[], int max, int front, int rear, int item) { if (rear + 1 == max) { printf("overflow"); } else { if(front == -1 && rear == -1) { front = 0; rear = 0; } else { rear = rear + 1; } queue[rear] = item; } }
For deletion, the algorithm is:
C program:
int delete (int queue[], int max, int front, int rear) { int y; if (front == -1 || front > rear) { printf("underflow"); } else { y = queue[front]; if(front == rear) { front = rear = -1; else front = front + 1; } return y; } } |
Reference