Experiment No 8.
Experiment No 8.
The array implementation can not be used for the large scale applications where the
queues are implemented. One of the alternatives of array implementation is linked list
implementation of queue.
In a linked queue, each node of the queue consists of two parts i.e. data part and the
link part. Each element of the queue points to its immediate next element in the
memory.
In the linked queue, there are two pointers maintained in the memory i.e. front pointer
and rear pointer. The front pointer contains the address of the starting element of the
queue while the rear pointer contains the address of the last element of the queue.
Insertion and deletions are performed at rear and front end respectively. If front and rear
both are NULL, it indicates that the queue is empty.
Insertion Algorithm
○ Step 4: END
Deletion Algorithm
○ Step 5: END
CODE:-
#include<stdio.h>
#include<stdlib.h>
struct node
{ int data;
void insert();
void delete();
void display();
void main ()
{ int choice;
while(choice != 4)
{ printf("\n*************************Main Menu*****************************\n");
printf("\n===============================================================
==\n");
scanf("%d",& choice);
switch(choice)
{ case 1:
insert();
break;
case 2:
delete();
break;
case 3:
display();
break;
case 4:
exit(0);
break;
default:
} } }
void insert()
int item;
if(ptr == NULL)
{ printf("\nOVERFLOW\n");
return; }
else {
printf("\nEnter value?\n");
scanf("%d",&item);
if(front == NULL)
{ front = ptr;
rear = ptr;
else {
rear = ptr;
rear->next = NULL;
} } }
void delete ()
if(front == NULL)
{ printf("\nUNDERFLOW\n");
return; }
else {
ptr = front;
free(ptr);
} }
void display()
ptr = front;
if(front == NULL)
{ printf("\nEmpty queue\n");
while(ptr != NULL)
} } }
OUTPUT:-