Linked List Implementation of Queue
In the linked queue, there are two pointers, the rear pointer and the front pointer. The front pointer contains the address of the first element while the rear pointer contains the address of the last element of the queue. Insertions are performed at the rear end and deletion is performed at the front end.
The algorithm for the insertion implementation is as follows:

The C program for insertion is as follows:
void insert(struct node *ptr, int item; ) { ptr = (struct node *) malloc (sizeof(struct node)); if(ptr == NULL) { printf("\nOVERFLOW\n"); return; } else { ptr -> data = item; if(front == NULL) { front = ptr; rear = ptr; front -> next = NULL; rear -> next = NULL; } else { rear -> next = ptr; rear = ptr; rear->next = NULL; } } } |
For deletion, the algorithm is:
The C program for deletion is as follows:
void delete (struct node *ptr) { if(front == NULL) { printf("\nUNDERFLOW\n"); return; } else { ptr = front; front = front -> next; free(ptr); } } |
Reference
