Computer Science, asked by shruthika9166, 1 year ago

How to represent Queue using Array, Explain?

Answers

Answered by rishavthakur27
0
To represent a queue using an array you need two index pointers: one for the head of the queue and one for the tail. Insertions are made by adjusting the tail pointer and deletions by adjusting the head pointer. If either pointer advances beyond the valid array index then it is set to the opposite end of the array (making the array circular).

A counter variable is usually unnecessary if we note that when the head pointer is equal to the tail pointer then the queue is empty while if the head and tail pointers differ by 1 then the queue is full. This presupposes that the head pointer points to the next element to be dequeued while the tail pointer points to the next vacant position.

Similar questions