5.2 Queue Prog by Array - Link List
5.2 Queue Prog by Array - Link List
Program Explanation
1. Ask the user for the operation like insert, delete, display and exit.
2. According to the option entered, access its respective function using switch statement.
Use the variables front and rear to represent the first and last element of the queue.
3. In the function insert(), firstly check if the queue is full. If it is, then print the output as
“Queue Overflow”. Otherwise take the number to be inserted as input and store it in the
variable add_item. Copy the variable add_item to the array queue_array[] and increment
the variable rear by 1.
4. In the function delete(), firstly check if the queue is empty. If it is, then print the output
as “Queue Underflow”. Otherwise print the first element of the array queue_array[] and
decrement the variable front by 1.
5. In the function display(), using for loop print all the elements of the array starting from
front to rear.
6. Exit.
#include <stdlib.h>
struct node {
int data;
};
if (ptr == NULL) {
printf("\nOVERFLOW\n");
return;
} else {
if (front == NULL) {
front = ptr;
rear = ptr;
} else {
rear = ptr;
rear->next = NULL;
int main() {
insert(head, 10);
insert(head, 20);
return 0;