This Linear (Sequential) Queue, is a linear list DATA STRUCTURE used to represent a linear list and permits deletion to be performed at one end of the list and the insertion at the other end. The information in such a list is processed in the same order as it was received, that is on first-come-first-out (FIFO) basis. The Railway Reservation counter is an example of queue where the people collect their tickets on the first-come-first-serve (FIFS) basis. There are two types of operations possible on the linear queue.
Two common ways in which queues may be implemented are as follows:
A queue has two pointers front and rear, pointing to the front and rear elements of the queue, respectively. Consider a queue Q consisting of n elements and an elements Value, which we have no insert into the Q. The value NULL (0) of front pointer implies an empty queue and the MAXVALUE implies the queue is full.
Insert operation inserting the new value from the rear side (right hand side). The first value is arranged in the queue as a left most value (in queue as first value) and second value is also inserted on rear side and set behind first value. Thus, each new value is set behind the previous entered value.
|Step 1: [Check overflow condition]if rear >= size
Output “Overflow” and return
Step 2: [Increment rear pointer]
Rear = rear + 1
Step 3: [Insert an element]
Q [rear] = value
Step 4: [Set the front pointer]
If front = 0
front = 1
Step 5: return
printf(“Your QUEUE is FULL…\n”);
printf(“Enter New Value :”);
Deletion Operation is used to remove the values in the queue. It is works on the first-in-first-out (FIFO) basis, means, it is removed item from the front side (at the right hand side of the queue). This operation is removed first entered item after second entered item and so on in the queue.
|Step 1: [Check underflow condition]if front = 0
Output “Underflow” and return
Step 2: [Remove an element]
Value = Q [front]
Step 3: [Check for empty queue]
If front = rear
front = 0
rear = 0
front = front + 1
printf(“Your QUEUE is EMPTY…\n”);
printf(“The Removed Item Is %d.\n”,remitem);