2. IMPLEMENTING QUEUES USING
LINKED LISTS
• Allocate memory for each new element dynamically
• Link the queue elements together
• Use two pointers, Front and Rear, to mark the front and
rear of the queue
Dr. SINDHIA LINGASWAMY, VIT
2
3. • In a linked queue, every element has two parts, one that stores the
data and another that stores the address of the next element.
• The START pointer of the linked list is used as FRONT.
• Here, we will also use another pointer called REAR, which will store
the address of the last element in the queue.
• All insertions will be done at the rear end and all the deletions will
be done at the front end.
• If FRONT = REAR = NULL, then it indicates that the queue is empty.
Dr. SINDHIA LINGASWAMY, VIT
3
4. ENQUEUING (EMPTY
QUEUE)
We need to make Front point to the new node
also
New Node
newNode
Dr. SINDHIA LINGASWAMY, VIT
4
6. DEQUEUEING (THE QUEUE
CONTAINS ONLY ONE ELEMENT)
• We need to reset Rear to NULL also
Nod
e
qFront
qRear
After dequeue:
qFront = NULL
qRear = NULL
Dr. SINDHIA LINGASWAMY, VIT
6