Array Implementation Of Queue

Arpit Kumar
2 min readJan 14, 2021

Queue(Abstract Data Type), We define it as a mathematical or logical model.

A Queue is a list of collection with this restriction with this constraint, that Insertion can be performed at one end, that we call rear of Queue/tail of Queue And Deletion can be performed at the other end that we call the front of Queue/head of Queue.

So we will be creating an array queue of size n with two variables top and end.

Initially, The array is empty , Both top and end would be at 0 indexes of the array. NOW,

Insertion: Before adding elements to queue, we will check if the queue is full or not. As we add elements(enqueue) , The value of end variable will be increasing. Max value attain by end will be n(Max length of array).

Deletion: Before deleting the elements of the queue, we will check if the queue is empty or not. As we delete elements(dequeue) , The value of top variable will be increasing. The value of top can go up to the value of the end.

Front: This is to get the first element of queue, that is array[top]. Just first check if the queue is empty or contain element/s.

Display: Just traverse the queue.

Drawback of array implementation

Memory wastage : The space of the array, which is used to store queue elements, can never be reused to store the elements of that queue because the elements can only be inserted at front end and the value of front might be so high so that, all the space before that, can never be filled.

To overcome this problem there is another variation of queue called Circular Queue, which ensures that the full array is utilized when storing the elements.

--

--