QUEUE USING LINKED LIST
QUEUE…
▪ Queue is a liner data structure which follows FIFO
(first in first out).
The two ends of a queue are called front & rear.
Insertion always takes place at the rear.
The elements are accessed or removed from front.
LINKED LIST…
we can do the queue operation using linked list instead
of the arrays . because, in arrays it has fixed size.
but in linked list.. it doesn’t has fixed size, so we can
add more number of elements and delete it too.
Generally, linked list is a linear data structure which is
made up of nodes connected together by pointers.
linked list are dynamic data structure in which
elements form a sequential list.
CONDITIONS FOR QUEUE…
In Queue..
If rear =MAX-1(queue is full)
And
front=NULL
rear=NULL (queue is empty)
an underflow condition occurs when we try to
delete the elements from queue that is already
empty.
QUEUE USING LINKED LIST….
In queues, we use 2 operations.
enqueue()
it is for insert the elements.
dequeue()
it is for delete the elements.
if we have only head pointer we cannot do
both enqueue and dequeue.
instead of head we will use front and rear
pointers.
ENQUEUE AND DEQUEUE OPERATION OF QUEUE...
ALGORITHMS FOR ENQUEUE..
Enqueue:
void enqueue(int value)
{
Node*ptr=new Node();
ptr->data=value;
ptr->link=NULL;
if(front==NULL)
{
Front=ptr;
rear=ptr;
}
else
{
rear->link=ptr;
Rear=ptr;
}
}
ALGORITHM FOR DEQUEUE…
Dequeue:
Void dequeue()
If(temp==NULL)
{
printf(“queue is empty!\n”);
return ;
}
temp=front;
printf(“%d dequeued .\n”,temp->data);
front=front->next;
If(front==NULL) //QUEUE BECOMES EMPTY
{
rear=NULL;
}
F
free(temp)
}
TYPES OF QUEUES…
simple queues
circular queues
priority queues
double ended queues(dequeues)
ADVANTAGES OF QUEUES USING LINKED LISTS…
dynamic resizing.
doesn’t consume more time.
efficient enqueue and dequeue operations.
no memory wastage.
used for networking and customer services.
THANK YOU……..