Queue is an abstract data structure, somewhat similar to Stacks. Unlike stacks, a queue is open at both its ends. One end is always used to insert data (enqueue) and the other is used to remove data (dequeue). Queue follows First-In-First-Out methodology, i.e., the data item stored first will be accessed first.
Queue operations may involve initializing or defining the queue, utilizing it, and then completely erasing it from the memory. Here we shall try to understand the basic operations associated with queues −
The following steps should be taken to enqueue (insert) data into a queue −
if(rear==max-1)
"overflow"
else
arr[max++]=val
if(front<0 || front >rear)
"underflow"
else
front++;